Here's an example of making a GET request using the Unirest library in Python:
import unirest # Make the GET request response = unirest.get("https://example.com/api/endpoint", headers={ "Accept": "application/json" }) # Print the status code print(response.code) # Print the headers print(response.headers) # Print the body print(response.body)
This example makes a GET request to the specified URL, with an "Accept" header set to "application/json" to indicate that the client is expecting a JSON response. The response object contains the status code, headers, and body of the response.
You can also pass additional parameters to the get()
method, such as a query string or form parameters. For example:
response = unirest.get("https://example.com/api/endpoint", headers={ "Accept": "application/json" }, params={ "param1": "value1", "param2": "value2" })
This will send a GET request with the specified query string parameters.