How to POST raw whole JSON in the body of a Retrofit request?

The @Body annotation defines a single request body. interface Foo { @POST(“/jayson”) FooResponse postJson(@Body FooRequest body); } Since Retrofit uses Gson by default, the FooRequest instances will be serialized as JSON as the sole body of the request. public class FooRequest { final String foo; final String bar; FooRequest(String foo, String bar) { this.foo = … Read more

How do I send a JSON string in a POST request in Go

I’m not familiar with napping, but using Golang’s net/http package works fine (playground): func main() { url := “http://restapi3.apiary.io/notes” fmt.Println(“URL:>”, url) var jsonStr = []byte(`{“title”:”Buy cheese and bread for breakfast.”}`) req, err := http.NewRequest(“POST”, url, bytes.NewBuffer(jsonStr)) req.Header.Set(“X-Custom-Header”, “myvalue”) req.Header.Set(“Content-Type”, “application/json”) client := &http.Client{} resp, err := client.Do(req) if err != nil { panic(err) } defer … Read more

Spring RestTemplate GET with parameters

To easily manipulate URLs / path / params / etc., you can use Spring’s UriComponentsBuilder class to create a URL template with placehoders for the parameters, then provide the value for those parameters in the RestOperations.exchange(…) call. It’s cleaner than manually concatenating strings and it takes care of the URL encoding for you: HttpHeaders headers … Read more

How to get body of a POST in php?

To access the entity body of a POST or PUT request (or any other HTTP method): $entityBody = file_get_contents(‘php://input’); Also, the STDIN constant is an already-open stream to php://input, so you can alternatively do: $entityBody = stream_get_contents(STDIN); From the PHP manual entry on I/O streamsdocs: php://input is a read-only stream that allows you to read … Read more

When do I use path params vs. query params in a RESTful API?

Best practice for RESTful API design is that path params are used to identify a specific resource or resources, while query parameters are used to sort/filter those resources. Here’s an example. Suppose you are implementing RESTful API endpoints for an entity called Car. You would structure your endpoints like this: GET /cars GET /cars/:id POST … Read more

Separate REST JSON API server and client? [closed]

At Boundless, we’ve gone deep with option #2 and rolled it out to thousands of students. Our server is a JSON REST API (Scala + MongoDB), and all of our client code is served straight out of CloudFront (ie: www.boundless.com is just an alias for CloudFront). Pros: Cutting-edge/exciting A lot of bang for your buck: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)