What is JSON?
What is HTTP GET?
The HTTP GET request method is used to request data-specified resources from the server. The HTTP GET method is one of nine standard HTTP (Hypertext Transfer Protocol) methods. HTTP GET requests should only receive data and do not change the server's state.
How to send a GET request to get JSON data?
The client indicates to the server a list of supported formats using the HTTP Accept header. For example, browsers send GET requests with the Accept header in the following format:
The server selects the appropriate content type and informs the browser of its choice using the Content-type response header.
GET request to get JSON data Example
To get JSON data, the client must explicitly indicate that it expects JSON data with the "Accept: application/json" header. If the Accept header is not present in the request, the server assumes that the client accepts all media types. Following is an example of getting JSON data from the ReqBin echo URL:
How to return a JSON response?
To return a JSON response, the client needs to include the JSON data in the body of the HTTP response message and specify the data type in the "Content-Type: application/json" header. Clients use the Content-Type response header to interpret the server response data correctly. Below is an example of a JSON response from the server: