Skip to content

Instantly share code, notes, and snippets.

@OliverJAsh
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OliverJAsh/e04ce1cb673d7c6771d0 to your computer and use it in GitHub Desktop.
Save OliverJAsh/e04ce1cb673d7c6771d0 to your computer and use it in GitHub Desktop.
API question

POST /feeds

{ "url": "<feedURL>" }

Description: Creates a feed from <feedUrl> by making a HTTP request to the feed URL and saving it to the database.

This operation will fail if (in order):

  1. Feed URL is an invalid URI (validation error)
  2. A feed already exists with the requested feed URL (must be unique: validation error)
  3. Feed URL does not resolve to a host
  4. The request to the feed URL returns a bad status code (e.g. 404)
  5. The response is not a feed, but something else (e.g. a HTML page)
  6. The response is a feed, but is missing a title (invalid feed: validation error(?))

Questions

For each of these potential failure areas, how should the API respond?

  1. Obivously a client error and should return a 400
  2. Obivously a client error and should return a 400
  3. The client input was valid, so what status code should this return?
  4. The client input was valid, so what status code should this return?
  5. The client input was valid, so what status code should this return?
  6. The client input was valid, so what status code should this return? Technically this is an error when validating the feed (the title is required).
@trygvis
Copy link

trygvis commented Nov 6, 2014

  1. should probably be 422 (http://httpstatus.es/422). The URL is syntactically OK, but not a valid business operation.
    3/4/5) ditto.

For these cases you can return a document explaining exactly what went wrong and how the client can fix it.

@trygvis
Copy link

trygvis commented Nov 6, 2014

Sometimes it is also useful for the server to ignore duplicate requests. If you're just storing the POSTed feed you could just return the created resource instead of failing. It makes it easier on the client as they can just retry their POST requests if they had any kind of error.

Another alternative is to let the client post to /feeds/{uuid} and store the UUID with the feed on the server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment