Questions tagged [http]

HyperText Transfer Protocol - a textual system for representing web requests and replies.

A method of structuring human-readable requests and replies of web servers and their clients which provides at least these features: 1) standardized numeric result codes 2) extensible options 3) statelessness 4) compatibility with networking - reply length known or ability to stream limited or unlimited replies. 5) encoding binary data in readable form.

371 questions
225
votes
3 answers

Why doesn't HTTP have POST redirect?

HTTP redirects are done via HTTP codes 301, and 302 (maybe other codes also) and a header field known as "Location" which has the address of the new place to go. However, browsers always send a "GET" request to that URL. However, many times you…
Saeed Neamati
  • 18,142
  • 23
  • 87
  • 125
136
votes
6 answers

Why shouldn't a GET request change data on the server?

All over the internet, I see the following advice: A GET should never change data on the server- use a POST request for that What is the basis for this idea? If I make a php service which inserts data in the database, and pass it parameters in…
Devdatta Tengshe
  • 2,514
  • 4
  • 21
  • 22
116
votes
8 answers

RESTful API. Should I be returning the object that was created / updated?

I'm designing a RESTful web service using WebApi and was wondering what HTTP responses and response bodies to return when updating / creating objects. For example I can use the POST method to send some JSON to the web service and then create an…
iswinky
  • 1,263
  • 2
  • 9
  • 8
113
votes
5 answers

Should I return an HTTP 400 (Bad Request) status if a parameter is syntactically correct, but violates a business rule?

Say that I have a REST endpoint that takes an integer as a parameter: /makeWaffles?numberOfWaffles=3 In this case, I want the number to be positive because I can't make a negative number of waffles (and requesting 0 waffles is a waste of time). So…
Thunderforge
  • 2,668
  • 3
  • 23
  • 30
90
votes
4 answers

What belongs in an HTTP request header vs the request body?

I'm working on a set of web services for a mobile client, and the requirements call for a unique device id to be included with all requests, to be stored in certain requests, and used to filter results in others. A suggestion was made that it be…
Mike Partridge
  • 6,587
  • 1
  • 25
  • 39
87
votes
8 answers

What HTTP status code to return if multiple actions finish with different statuses?

I am building an API where the user can ask the server to perform multiple actions in one HTTP request. The result is returned as a JSON array, with one entry per action. Each of these actions might fail or succeed independently of each other. For…
Anders
  • 1,321
  • 1
  • 10
  • 17
84
votes
6 answers

HTTP Status Code for "Still Processing"

I'm building a RESTful API that supports queuing long-running tasks for eventual handling. The typical workflow for this API would be: User fills in form Client posts data to API API returns 202 Accepted Client redirects user to a unique URL for…
Matthew Haugen
  • 1,045
  • 1
  • 8
  • 11
83
votes
4 answers

Should I use HTTP status codes to describe application level events

Several servers I have dealt with will return HTTP 200 for requests that the client ought to consider a failure, with something like 'success : false' in the body. This does not seem like a proper implementation of HTTP codes to me, particularly in…
Kagan Mattson
  • 941
  • 1
  • 7
  • 5
78
votes
3 answers

Trailing slash in RESTful API

I have been having a debate about what to do with a trailing slash in a RESTful API. Lets say I have a resource called dogs and subordinate resources for individual dogs. We can therefore do the following: GET/PUT/POST/DELETE…
GWed
  • 3,085
  • 5
  • 26
  • 43
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
4 answers

Why PATCH method is not idempotent?

I was wondering about this. Suppose I have a user resource with id and name fields. If I want to update a field I could just do a PATCH request to the resource like this PATCH /users/42 {"name": "john doe"} And then the application will update…
seldon
  • 952
  • 1
  • 7
  • 13
70
votes
2 answers

How should a REST API handle PUT requests to partially-modifiable resources?

Suppose a REST API, in response to a HTTP GET request, returns some additional data in a sub-object owner: { id: 'xyz', ... some other data ... owner: { name: 'Jo Bloggs', role: 'Programmer' } } Clearly, we don't want anyone to be…
Robin Green
  • 1,233
  • 1
  • 9
  • 22
64
votes
5 answers

What does HATEOAS offer for discoverability and decoupling besides ability to change your URL structure more or less freely?

Lately I've been reading about Hypermedia as the Engine of Application State (HATEOAS), the constraint that is claimed to make a web API "truly RESTful". It boils down to basically including links with every response to the possible transitions you…
Botond Balázs
  • 1,463
  • 2
  • 12
  • 13
52
votes
10 answers

What should be the http status code for "Service not available in your area" error?

Our service is in 5 cities right now. If someone tries to call our service API from any other city, we want to throw this error Service not available in your area. The question is, what is the appropriate http code would be for this error? 503:…
Shaharyar
  • 865
  • 2
  • 7
  • 12
47
votes
2 answers

Suggested HTTP REST status code for 'request limit reached'

I'm putting together a spec for a REST service, part of which will incorporate the ability to throttle users service-wide and on groups of, or on individual, resources. Equally, time-outs for these would be configurable per…
Andras Zoltan
  • 901
  • 2
  • 7
  • 15
1
2 3
24 25