What is an API response?
An API response is the information returned to an app from a server following an API request.
When an app or web browser makes an API request, the server processes the request and creates a response that contains the requested information. This allows the app to use the API server's data, services, or functionalities.
Elements included in API responses
HTTP status code: The outcome of the API request is indicated by a three-digit code. Common HTTP (Hypertext Transfer Protocol) status codes include:
200 OK: The request was successful, and the server returned the requested data
201 Created: The request was successful, and a new resource was created
400 Bad Request: The request was invalid or malformed
401 Unauthorized: The client application lacks valid authentication credentials for the requested resource
404 Not Found: The requested resource could not be found on the API server
500 Internal Server Error: An error occurred on the server while processing the request
Headers: Headers provide additional metadata about the API response, including the content format (e.g. JSON), encoding, or authentication status.
Response body: The response body is the main content of the API response and contains the information requested by the application. Depending on the API design, the response body uses a common data format, such as JSON, XML, or plain text.
Error messages: In the case of an error or an unsuccessful request, the API response may include error messages or codes that provide information about what went wrong to help the client application understand and handle the error appropriately.
Say your app uses the Sendbird Chat API to retrieve the chat history for a user. The API response for a successful request would look something like this:
The example above shows that the API request was successful and provided the requested user information in the JSON format.
To recap, API responses provide apps with the information they need to perform tasks, display data, and interact with services provided by the API.
Build your in-app communications without the challenge.