Should I URL-encode POST data?

General Answer The general answer to your question is that it depends. And you get to decide by specifying what your “Content-Type” is in the HTTP headers. A value of “application/x-www-form-urlencoded” means that your POST body will need to be URL encoded just like a GET parameter string. A value of “multipart/form-data” means that you’ll … Read more

Paging in a Rest Collection

I don’t really agree with some of you guys. I’ve been working for weeks on this features for my REST service. What I ended up doing is really simple. My solution only makes a sense for what REST people call a collection. Client MUST include a “Range” header to indicate which part of the collection … Read more

Go doing a GET request and building the Querystring

As a commenter mentioned you can get Values from net/url which has an Encode method. You could do something like this (req.URL.Query() returns the existing url.Values) package main import ( “fmt” “log” “net/http” “os” ) func main() { req, err := http.NewRequest(“GET”, “http://api.themoviedb.org/3/tv/popular”, nil) if err != nil { log.Print(err) os.Exit(1) } q := req.URL.Query() … Read more

What is the appropriate HTTP status code response for a general unsuccessful request (not an error)?

You should use 400 for business rules. Don’t return 2xx if the order was not accepted. HTTP is an application protocol, never forget that. If you return 2xx the client can assume the order was accepted, regardless of any information you send in the body. From RESTful Web Services Cookbook: One common mistake that some … Read more

What is the X-REQUEST-ID http header?

When you’re operating a webservice that is accessed by clients, it might be difficult to correlate requests (that a client can see) with server logs (that the server can see). The idea of the X-Request-ID is that a client can create some random ID and pass it to the server. The server then include that … Read more

Proper REST response for empty table?

I’d say, neither. Why not 404 (Not Found) ? The 404 status code should be reserved for situations, in which a resource is not found. In this case, your resource is a collection of users. This collection exists but it’s currently empty. Personally, I’d be very confused as an author of a client for your … Read more

REST, HTTP DELETE and parameters

No, it is not RESTful. The only reason why you should be putting a verb (force_delete) into the URI is if you would need to overload GET/POST methods in an environment where PUT/DELETE methods are not available. Judging from your use of the DELETE method, this is not the case. HTTP error code 409/Conflict should … Read more