toosensitive toosensitive - 2 months ago 16
reST (reStructuredText) Question

Best practice on Return type of rest web api

I have a get rest api, which will return a list of objects in json format

What is best practice for return type of a rest api?

Which one should I use? Thanks

public HttpResponseMessage MyGetMethod(int acctId, string userId)
public HttpMyObjectResponse MyGetMethod(int acctId, string userId)


In general HttpResponseMessage is better because you can do things like set the status code, add additional headers, etc. in the response.

Say the userId that was passed in doesn't exist. Then you could do something like

return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "That user does not exist");