Questions tagged [http-response]

64 questions
75
votes
9 answers

When to use HTTP status code 404 in an API

I am working on a project and after arguing with people at work for about more than a hour. I decided to know what people on stack-exchange might say. We're writing an API for a system, there is a query that should return a tree of Organization or a…
Loïc Faure-Lacroix
  • 1,634
  • 3
  • 16
  • 19
70
votes
6 answers

Should "No Results" be an error in a RESTful response?

I'll describe an example: I start making an API for a baking shop. The API will allow people to search their catalogus for baking products, such as home-made minty chocolate chip cookies using api.examplebakery.com/search?q=...... Someone uses this…
Berry M.
  • 829
  • 1
  • 6
  • 6
55
votes
7 answers

Why do so many standards for JSON API response formats contain a "success" property in the response body instead of just using HTTP status codes?

I was researching about best practices for standardised JSON response formats for APIs, according to various sources available online general consensus looks something like this: //Successful request: { "success": true, "data": { /*…
49
votes
11 answers

Should a REST API return a 500 Internal Server Error to indicate that a query references an object that does not exist?

I am working with a REST API which resides on a server that handles data for a multitude of IoT devices. My task is to query the server using the API to collect specific performance information about said devices. In one instance, I obtain a list of…
JYelton
  • 734
  • 1
  • 6
  • 12
41
votes
4 answers

Any technical reason not to use my own HTTP response code TEXT if I develop both server & Client?

Over the years, I have seen quite a few questions on this site along the lines of "can I invent my own HTTP response codes"? Generally asked by those who are developing both the server and client. The responses tend to go towards sticking with…
25
votes
2 answers

Levels of user permissions in a RESTful API

Let's say I have a company that ranks the cutest cats on the internet. I offer a resource at /cats/ which provides users with the latest, cutest adorable cats. Users can either get just the top 3 cats if they haven't paid at all or registered. The…
Benjamin Gruenbaum
  • 5,157
  • 4
  • 24
  • 34
11
votes
2 answers

What are some best practices for cookie based web authentication?

I'm working on a small side project using CGI and Python (scalability is not an issue and it needs to be a VERY simple system.) I was thinking of implementing authentication using cookies, and was wondering if there were any established best…
rdasxy
  • 3,323
  • 7
  • 29
  • 41
10
votes
1 answer

Use 404 or 200 when null result (REST)

Let's assume we have an Entity { "id": 1 "inProgress": true, } We have endpoints: /api/v1/entities/ for fetching all entities, /api/v1/entities/1 for fetching entity with id = 1 /api/v1/entities/in-progress for fetching entity which is in…
Maxian Nicu
  • 217
  • 2
  • 3
8
votes
1 answer

Rendering head :ok vs head :no_content. Any good practices?

Whenever I take in data and do something like delete a post, etc. I generally return head :no_content. For example: def destroy @post = Post.find_by(external_id: params[:post_id]) @post.destroy! head :no_content end Is it good practice to…
David
  • 219
  • 1
  • 2
  • 5
7
votes
2 answers

Is repeating an identifier on an API request and response considered a code smell

Is it weird to have an identifier such as (_id) on a request which you send to the API, which "enriches" the request and sends back a response with the same identifier (but obviously more enriched data)? For example - you send request {_id: 1111}…
AvetisCodes
  • 1,544
  • 3
  • 14
  • 26
7
votes
1 answer

RESTful HTTP OPTIONS request content

I'm having trouble determining what I might put in the body of a response to an OPTIONS request? are there conventions? standards? What do you put? do you just provide a list of other METHODS? should you give the representation?
xenoterracide
  • 1,223
  • 1
  • 10
  • 21
6
votes
1 answer

Whatever happened to HTTP SEARCH?

It seems 5 years ago there was a proposal for a HTTP SEARCH request, but it does not appear to have been adopted and it not widely supported. Are there any factual documents or citations which shed light on the reasoning behind why SEARCH has not…
chrispepper1989
  • 327
  • 2
  • 8
5
votes
4 answers

What are the benefits of using meta tag/JavaScript redirection over HTTP header redirection?

Upon inspecting Twitter's URL shortening service http://t.co, I noticed that, instead of redirecting to the goal URL using a Location HTTP header and a 3xx HTTP status code, it redirects using the following HTML (formatted for better…
Decent Dabbler
  • 570
  • 2
  • 16
5
votes
3 answers

Is Model a better place to set HTTP status code?

In MVC usually the controller sets whatever needs to be sent back to the client/View, including HTTP status code, e.g.: class Controller { public function get(Request req, Response resp) { if (this.model.get(req.getId()) { …
imel96
  • 3,488
  • 1
  • 18
  • 28
5
votes
3 answers

Web Service and Message Queue

We're looking at creating a web services/REST API layer that will be consumed by web and mobile clients. To make the solution more robust I was considering putting the commands from PUT, POST, and PATCH onto a message queue, which would mean that…
1
2 3 4 5