DevNet Associate (DEVASC) v1.0Understanding and Using APIsHard
A developer is performing API testing and needs to send a series of HTTP requests to a REST API. Each request requires a different set of query parameters and occasionally a different request body, but the base URL and authentication headers remain constant. Which cURL command line feature is best suited for reusing common request parts while varying others?
- A`--config` to load common options from a file.
- B`--data-urlencode` for dynamic body content.
- C`--request` to specify the HTTP method.
- D`--header` to set dynamic headers per request.
Show answer & explanationAnswer & explanation
Correct answer: A. `--config` to load common options from a file.
The `cURL --config` option allows users to specify a file containing cURL command-line options. This is extremely useful for defining common parameters like base URLs, authentication headers, and default methods once, and then reusing them across multiple cURL calls while only specifying the unique parts (like specific query parameters or request bodies) directly on the command line or in other config files.
Why the other options are wrong
- B. `--data-urlencode` is for sending URL-encoded data, not for reusing common parts.
- C. `--request` (or `-X`) specifies the HTTP method for a single request, not for reusing common parts.
- D. `--header` sets a header for a single request, not for reusing common headers across multiple distinct commands.
cURL --config Option
A cURL command-line option that reads configuration from a specified file, allowing users to define and reuse common arguments across multiple cURL commands.
- Enhances reusability and reduces command-line length for complex cURL calls.
- Config files can contain any cURL option, one per line or separated by spaces.
- Useful for managing API keys, base URLs, and common headers.
Memory trick: Don't type it again! Put the common parts in a cookbook (config file).