api response codes code example

Example 1: api error codes

General (unknown) error.	                              = 500
	Customer account not found (possible bad subdomain	      = 401
	Customer account inactive	                              = 401
	Customer account suspended	                              = 503
	Customer account banned	                                  = 418
	Paid customer account inactive due to non-payment	      = 402
	User not found	                                          = 401
	User not active	                                          = 401
	Invalid auth (bad username/password)	                  = 401
	Permissions error.                    	                  = 403
	Maximum number of daily API requests exceeded          	  = 400

Example 2: http status codes

2xx :  SUCCESS 
				200 OK : success 
				201 CREATED : successfully added data 
				204 NO-CONTENT successfully updated or deleted 
            
            3xx : REDIRECTION
            	304 NOT MODIFIED: 

			4xx :  CLIENT SIDE ERROR 
				400 BAD REQUEST : bad data being sent 
                401 UNAUTHORIZED : 
                403 FORBIDDEN :
				404 NOT FOUND : the resource does not exists at that location 
				405 METHOD NOT ALLOWED :
						DELETE /api/spartans -->> 405 error 
				406 NOT ACCEPTABLE
				415 Unsupported Media type
					if you forget to specify the Content-Type
					of Post request body, it will see it as plain text
					and it will throw this error if it does not support
			
			5xx : Server side error 
				500 internal service error 	
				If the server do not have any mapping of the url 
				requested to handle the action -->> 500
                503 SERVICE UNAVAILABLE :
                504 GATEWAY TIMEOUT :

Example 3: what should be the error response status for information message

Status-Code    =
            "100"  ; Section 10.1.1: Continue
          | "101"  ; Section 10.1.2: Switching Protocols
          | "200"  ; Section 10.2.1: OK
          | "201"  ; Section 10.2.2: Created
          | "202"  ; Section 10.2.3: Accepted
          | "203"  ; Section 10.2.4: Non-Authoritative Information
          | "204"  ; Section 10.2.5: No Content
          | "205"  ; Section 10.2.6: Reset Content
          | "206"  ; Section 10.2.7: Partial Content
          | "300"  ; Section 10.3.1: Multiple Choices
          | "301"  ; Section 10.3.2: Moved Permanently
          | "302"  ; Section 10.3.3: Found
          | "303"  ; Section 10.3.4: See Other
          | "304"  ; Section 10.3.5: Not Modified
          | "305"  ; Section 10.3.6: Use Proxy
          | "307"  ; Section 10.3.8: Temporary Redirect
          | "400"  ; Section 10.4.1: Bad Request
          | "401"  ; Section 10.4.2: Unauthorized
          | "402"  ; Section 10.4.3: Payment Required
          | "403"  ; Section 10.4.4: Forbidden
          | "404"  ; Section 10.4.5: Not Found
          | "405"  ; Section 10.4.6: Method Not Allowed
          | "406"  ; Section 10.4.7: Not Acceptable

Example 4: 200 error code

The HTTP 200 OK success status response code indicates that the request has succeeded. A 200 response is cacheable by default. The meaning of a success depends on the HTTP request method: GET : The resource has been fetched and is transmitted in the message body.

from developer.mozilla.org

Example 5: response api

RESPONSE :(STATUS CODE,PAYLOAD(body),HEADER,COOKIE,
           TIME(spent to get response))

1-Status Code:
   2xx - Success
   4xx - Client Error
   5xx - Server Error

2-Payload(Body) : 
The actual resource we got from the server.
Content type can be : plain text, json, xml, html, json etc.

3- Metadata about response to provide more information

4- Cookie

5- Time for getting spended time for the response

Example 6: api response

Response 
				
				 Status code 
				 			2xx -->>  success 
				 			4xx -->>  client side error
				 			5xx -->>  server side error 
				 Header 
				 		meta data about your response 
				 		like Content-Type, Date and some other info

				 Body | Payload		
				 		The response we got from the server 
				 		and this where we do lots of validation

Tags:

Html Example