beginner·11 min read·Updated

How to Test API with cURL: Paste, Import, Upload

Paste a cURL command and get an endpoint and a test that sends what the command sends. See what a paste cannot carry, import a specification as text, and test forms and file uploads.

This is lesson 9.35 of Shift-Left API in Depth, the product track of the learning center. The earlier lesson is working with many requirement documents. Importing by pasting and file uploads are in every edition, Free included, within each edition's endpoint limit.

How to test API with cURL, and keep testing it?

The first step in how to test API with cURL is a command that works, perhaps copied from your browser, a vendor's docs or a teammate's message. But running it again by hand is not a test. When you paste it into Shift-Left API, the method and path become an endpoint, the host becomes its server, the query string becomes parameters and a JSON body becomes its schema. You also get a test that sends what the command sends.

How do you paste a cURL command?

  1. Open the project and click Endpoints in the sidebar.
  2. Choose Paste cURL or Text.
  3. Paste the command and click Import.
  4. Open the new test and click Run.

The test says it was imported from cURL and checks for a 200 status. Change that check if your API returns something else, and add more as in the test workbench.

If the request changes, paste the new command. The same endpoint and test are updated, not duplicated. A paste only adds to the project, so there is no change review to approve. Several commands can be pasted at once.

What can a paste carry, and what can't it?

Credentials in headers, such as an API key, come with the request and are stored on the test as pasted. The import tells you so. For anything long-lived, move them to an authentication profile.

Some things are named in a warning instead:

  • A file in a form field is not carried. The field is created, and you choose the file.
  • Digest sign-in has no header to copy, so its credentials are not imported. Set it up on an authentication profile.

A command with no URL is refused with the reason; a URL is never guessed from a stray word. An address without a scheme gets HTTP for localhost and HTTPS otherwise.

Can you paste a whole specification?

Yes. The same box accepts an OpenAPI, Swagger or Postman document as text, and a single web address is fetched. A specification creates endpoints and no tests, because it describes endpoints rather than saved requests. See also Postman import.

Import an unchanged specification again and you see No changes found. Cancel leaves the project as it is, and Update anyway re-imports over the same endpoints without a new version. A changed specification goes to review, as in spec change detection.

How do you test file uploads and forms?

A REST test body can be JSON or text, a URL-encoded form (common for login and token endpoints), a multipart form with text and files, or one file as the whole body.

For a multipart upload, open the test's Request Body, click Choose file and pick it. The file is stored in the project, and the test keeps a reference to it. You can replace or remove it, and uploading the same file twice keeps one copy. A new test must be saved once before you choose a file.

Check what the API says it received. In the video, a Field Equals assertion on received.contentType expects image/png. The sample upload API also answers with a size and a checksum; checking the checksum shows whether the file arrived intact. The run record describes the part sent, with the file's name, type and size, and does not keep its contents.

Uploads described in a specification work too. On Auto, the editor shows how the body will be sent and why. If a file value still sits in the JSON body, click Move them into this table. Without a chosen file, that multipart field is sent as its value in a small text file, and the Logs tab says so.

How do you send a whole file or a URL-encoded form?

Choose the File body type when one file is the whole request, such as replacing a PDF. The file's type becomes the content type unless you set one under Headers, so remove a header that should not override it. In this mode, a missing file stops the test before anything is sent.

For a URL-encoded form, edit the fields under Request Body. Values accept dynamic values, and Add field adds a row. This kind of form cannot carry a file, so use multipart for uploads.

Try it yourself

Paste a command you use and run its test. Then paste one with a file field and choose the file. Finally, import a specification twice. The cURL paste works with any API you can reach; the video's upload examples use a small local demo program.

Recap

  • A pasted command becomes an endpoint and a test.
  • Move long-lived credentials to an authentication profile.
  • A paste cannot carry local files, and it warns you.
  • A pasted specification creates endpoints; an unchanged one prompts you first.
  • Tests can send JSON, URL-encoded forms, multipart forms or whole files.

That is the latest lesson in this track. Browse the whole course, or compare cURL and Postman for API testing.

Hands-on lab

Try it: Paste a cURL command you already use and run the test it makes. Paste one with a file field, choose the file and add a check on the response. Then import a specification as text twice.

Enter your email to open the lab steps. One unlock opens every lab in the learning center.

No spam. Protected by reCAPTCHA — Google Privacy & Terms.

Frequently asked questions

What is cURL in API testing?+

cURL is a command-line tool for sending HTTP requests, and many API docs and browser tools give you requests as cURL commands. It is a quick way to try a call. To make it a test, you also need a saved request with checks that you can run again.

How to test API endpoint using cURL and keep the test?+

In Shift-Left API, open the import dialog, choose Paste cURL or Text, paste the command and click Import. You get an endpoint and a test that sends what the command sends. Run the test, then add more checks.

Can a pasted cURL command carry the file for a multipart file upload API test?+

No. A paste carries the command, not the file on someone's computer. The file field is created, and you choose the file on the test before running it.

Read more on the blog