Contents
- 1 When do you need to return a body in an API?
- 2 When to return actionresult instead of specific type?
- 3 What should I expect from a RESTful API?
- 4 What should be the status of a query with 0 results?
- 5 What does it mean when a query returns more than one result?
- 6 How to retrieve entity record using web API?
When do you need to return a body in an API?
If you design your API in such a way that it always returns a sensible response code, you might not even need to return a body when the resource was not found. That said, returning a body, especially a humanly readable one, can’t hurt.
When to return actionresult instead of specific type?
Unexpected conditions can occur during action execution, in which case the specific type isn’t returned. For example, an action’s input parameter may fail model validation. In such a case, it’s common to return the appropriate ActionResult type instead of the specific type.
What should I expect from a RESTful API?
The first thing to consider, since you are building a RESTful API, is to return an appropriate response code. And the more appropriate response code to communicate that the request went through normally, but the requested resource is not available at the moment is the venerable 404.
What happens when you return a string in ASP.NET?
Returning a string delivers Content-Type of text/plain: For actions with multiple return types, return IActionResult. For example, returning different HTTP status codes based on the result of operations performed. Content negotiation occurs when the client specifies an Accept header.
Is there a way to return more than one result set?
Basically your query returns more than one result set. In API Docs uniqueResult () method says that Convenience method to return a single instance that matches the query, or null if the query returns no results uniqueResult () method yield only single resultset
What should be the status of a query with 0 results?
Then for a query with 0 results, it should be this: If you also include meta data about how many “pages” of results there are, links to those “pages”, etc. then I would suggest saying there is 1 “page”. The HTTP status should be the same as when there are results – 200 OK.
What does it mean when a query returns more than one result?
It means that the query you wrote returns more than one element (result) while your code expects a single result. Basically your query returns more than one result set.
How to retrieve entity record using web API?
When retrieving a table row (entity record) you can also request specific properties and expand navigation properties to return properties from related tables. For information about retrieving table definitions, see Query table definitions using the Web API.
What should be included in response to / API / users?
While the response to /API/users is paged and returns only 30, records, there’s nothing preventing you from including in the response also the total number of records, and other relevant info, like the page size, the page number/offset, etc. The StackOverflow API is a good example of that same design.