curl tagged requests and articles

Categorized request examples and articles tagged with [curl] keyword
Curl Request With Bearer Token Authorization Header
An example of a Curl request with Bearer Token Authorization header. The bearer token is sent to the server in the 'Authorization: Bearer {token}' authorization header. The 'Accept: application/json' header tells the server that the client expects a JSON. The server informs the client that it returned a JSON with 'Content-Type: application/json' response header.

Curl POST JSON Example
An example of a Curl command to post JSON to the API endpoint. To post JSON with Curl, you need to set the content type to application/json. This is done by the -H "Content-Type: application/json" command-line option. The JSON is passed with the curl -d option. Double quotes in JSON are escaped with \".

Curl Get URL
An example of getting a URL with Curl. The target URL is passed as the second command line parameter. Curl automatically selects the GET method to use unless the -X, --request, and -d command-line options are used. The Accept: */* header is automatically added by Curl to the request header.

Curl GET JSON Example
An example of a Curl command to get JSON from the server. The Accept: application/json request header is passed to the server with the curl -H command-line option and tells the server that the client is expecting JSON. The server indicates that it has returned JSON data with a Content-Type: application/json response header.

Curl POST Form Example
An example of a Curl command to post a form in a URL-encoded format. The form data is passed as key/value pairs with -d curl command-line parameter. The Content-Type header application/x-www-form-urlencoded specifies the media type of the resource as urlencoded form data.

Curl POST XML Example
An example of a Curl command to post an XML string to the API endpoint. In this post XML request example, the 'Content-Type: application/xml' request header indicates that the request body contains an XML. The 'Accept: application/xml' request header tells the server that the client expects an XML. The XML is passed in the Curl -d command-line parameter.

Convert Curl to HTTP Request
Convert Curl command to the HTTP request. Enter your Curl request, click the Submit button to check if you entered the Curl command correctly, and then switch to the Raw tab to see the generated HTTP request. You can also convert Curl request to PHP, Python, JavaScript, and C # code. To convert a Curl request to Python code, click Code, and select Python.

Curl GET XML Example
An example of a Curl command to get and an XML data from the API endpoint. The Accept: application/xml request header tells the server that the client expects an XML response. The Content-Type: application/xml response header informs the client that the server returned an XML string.

Curl Command With Basic Server Authentication Header
An example of a Curl command with basic auth credentials. The user authentication credentials are passed with --user "login:password" Curl command line parameter. Curl automatically converts the "login:password" pair to the Base64 encoded string and adds the 'Authorization: Basic bG9naW46cGFzc3dvcmQ=' header to the request.

Curl OPTIONS Request
An example of sending an OPTIONS request with Curl. Browsers send OPTIONS requests when making a CORS request to another origin. To make an OPTIONS request using Curl, you must pass the -X OPTIONS command-line parameter to the Curl. The OPTIONS request does not return any data. All information is returned in the response headers.

Curl Command With Close Connection Header
This example shows how to send a Curl request to the server and indicate that the client does not want to keep the connection open by sending the Connection: close header. The header is passed with the curl -H command-line option.

Curl POST Request
An example of making a POST request using Curl. The -X POST command line parameter tells Curl to use the POST method for this request. The -d command line parameter contains the data to send to the server. The Curl -H "Content-Type: application/json" command line parameter specifies the media type of the resource in the request body.

Curl PATCH JSON String
An example of a Curl command for sending a PATCH request with JSON data to the REST API endpoint. In this HTTP PATCH request example, the Content-Type request header indicates the media type of the PATCH request. The JSON data is passed with the Curl -d command-line parameter.

Send Custom Headers with Curl
An example of posting a custom header with Curl. To add a custom header to curl, you need to pass the -H "header: value" command line parameter to the curl request. The target url is passed as the first parameter.

Curl Command With Keep-Alive Connection Header
An example of a Curl request with connection and keep-alive headers. The Connection header is passed with the -H "Connection: keep-alive" command-line parameter. The Keep-Alive header is passed with the -H "Keep-Alive: timeout=5, max=100" command-line parameter.

Curl GET Request
An example of making a GET request using Curl. Curl automatically selects the GET method unless the -X, --request, or -d command-line options are passed. The target URL is passed as the first command-line parameter. The second command-line parameter tells the server that the Curl client is expecting JSON.

Curl PUT JSON Example
An example of Curl command for updating a resource on the server by sending a PUT request with JSON data to the REST API endpoint. The Content-Type: application/json request header specifies the media type of the resource in the HTTP PUT message body.

Curl Add Header
An example of adding a header to the Curl request. Use the -H command-line option to set the Curl header details. In this Curl Add Header example, the -H "Content-Type: application/json" command-line option indicates the media type of the resource, and the Accept: application/json header tells the server that the client expects JSON.

Curl DELETE Request Example
An example of sending a DELETE request with Curl. In this Curl delete request example, the -X command-line option indicates the DELETE method, and the -H command-line option passes and custom HTTP header to the server.

Curl CORS Request
An example of sending a Curl request with the CORS Origin header (Cross-Origin Resource Sharing request). For CORS requests, the Origin header indicates where the request is coming from. In this Curl CORS Request example, the Origin header is passed to the server with the -H "Origin: https://example.reqbin.com" command-line option.

Curl POST With Basic Authentication
An example of making a POST request with basic authentication credentials using Curl. The basic authentication credentials are passed with the --user "login:password" command-line parameter. The POST data are passed with the -d parameter.

Curl Send Cookies
An example of sending cookies with Curl. Cookies are passed to Curl with the --cookie "Name = Value" command-line parameter. Curl automatically converts the passed parameter into the Cookie: Name=Value request header.

Curl Request With Credentials
Sample Curl request with Origin CORS request header and authorization cookie. In this Curl Request With Credentials example the Origin request header is passed with the -H "Origin: https://example.reqbin.com" command-line parameter and the cookie is passed with the --cookie "authCookie = my_auth_cookie" parameter.

curl -u
A live example of sending Curl command with Basic server authentication header (credentials are provided with -u or --user command-line argument).

curl -d
An example of sending data to the server with Curl. The data is passed with the -d command-line parameter. In this curl -d example, the -H command-line option explicitly specifies the content type in the request body.