djm.im
djm.im

Reputation: 3323

Which HTTP code should return as status?

I need to create REST API endpoint, and I am not sure which HTTP code to return as status.

Requirements are next:
- My API should accept URL as a parameter
- Make an API call to third-party service (use URL), and get a response
- Return response (content that fetched from third-party service)

In some cases, everything works fine. A call is made to external service, it returns content and status code 200.

But, sometimes there is no content and it returns 404. (Important, it is possible that content will be available in the future.)
From the perspective of my system, it is the regular situation.

Which HTTP code should I return?
202 - Accepted,
204 - No content,
206 - Partial content
or something else?

Upvotes: 1

Views: 120

Answers (3)

user3187479
user3187479

Reputation: 84

Instead of creating the actual resources, create a temporary one. Instead of returning a 201 (Created) HTTP response, you can issue a 202 (Accepted) response code. This informs the client that the request has been accepted and understood by the server, but the resource is not (yet) created.

From: http://restcookbook.com/Resources/asynchroneous-operations/

Upvotes: 1

MD Ruhul Amin
MD Ruhul Amin

Reputation: 4502

404 Not Found

The requested resource could not be found but may be available in the future. Subsequent requests by the client are permissible.

In REST-API request and response should only work with current "call". If the content is currently not available it should return 404 status. And It(404) is the exact status that should be returned.


However, if you want to bend the rules, 204 status code seems more appropriate. I'm not recommending you to do this.

204 No Content

The server successfully processed the request and is not returning any content Link.

Upvotes: 1

CoolMandy
CoolMandy

Reputation: 11

You should return whatever the HTTP status code return by third party service unless your system is wrapping it up and processing it and changing the status.

Upvotes: 0

Related Questions