Skip to content
API & TESTING TOOLS

HTTP Request Builder – Fetch, cURL & PHP

Generate Fetch, cURL and PHP request examples.

  • Free
  • No signup
  • Runs in your browser

This tool runs in your browser. The text you enter is processed on your device and is not sent to NHP Learning.

HTTP Request Builder

About HTTP Request Builder

Once you know which request an API needs, you still have to write it in each language you use. Describe the request once, as a simple HTTP message, and this tool generates the same call as a JavaScript fetch() snippet, a cURL command and PHP cURL code.

The first line holds the method and URL, the lines after it are headers, and anything after a blank line is the body. GET, POST, PUT, PATCH and DELETE are supported. The tool only writes code; it does not send the request, so API keys you type never leave your browser.

How to use HTTP Request Builder

  1. Write the method and URL, for example GET https://api.example.com/users?limit=5.
  2. Add headers on the following lines, and a body after a blank line if needed.
  3. Click Run Tool and copy the snippet you need.

Example

Input

GET https://api.example.com/users?limit=5
Accept: application/json

Output

// Fetch API
fetch('https://api.example.com/users?limit=5', {
  method: 'GET',
  headers: {
    'Accept': 'application/json'
  }
})
  .then((response) => response.json())
  .then((data) => console.log(data))
  .catch((error) => console.error(error));

# cURL
curl \
  -H 'Accept: application/json' \
  'https://api.example.com/users?limit=5'

// PHP (cURL)
$ch = curl_init();
curl_setopt_array( $ch, array(
    CURLOPT_URL            => 'https://api.example.com/users?limit=5',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT        => 15,
    CURLOPT_HTTPHEADER     => array(
        'Accept: application/json',
    ),
) );
$response = curl_exec( $ch );
if ( curl_errno( $ch ) ) {
    echo 'cURL error: ' . curl_error( $ch );
}
curl_close( $ch );

Common uses

  • Documenting an endpoint with examples in three languages.
  • Moving between a terminal test and application code.
  • Preparing a request for a teammate who uses a different language.

Privacy and safety

This tool runs in your browser. The text you enter is processed on your device and is not sent to NHP Learning.

Frequently asked questions

Does this send the request?

No. It only generates code. To make a public GET request from the server, use the REST API GET Tester.

How do I add a JSON body?

Add a Content-Type: application/json header, leave a blank line, then paste the JSON.

Which output should I use in WordPress?

The PHP snippet uses raw cURL. In WordPress plugins and themes, wp_remote_request() is the recommended way, and you can copy the URL, headers and body from the snippet.

Learn to build this yourself

Free tutorials and courses on NHP Learning cover PHP, JavaScript, SQL and WordPress, from the basics to real projects.