Basics of Dothttp Requests
#
Supported HTTP MethodsDothttp supports a wide range of HTTP methods, enabling you to interact with web services effectively. The supported methods include:
GET
POST
OPTIONS
DELETE
CONNECT
PUT
HEAD
TRACE
PATCH
COPY
LINK
UNLINK
PURGE
LOCK
UNLOCK
PROPFIND
VIEW
The syntax for specifying an HTTP request is as follows: <METHOD> <URL>
. For example, GET https://req.dothttp.dev
represents a GET
request to https://req.dothttp.dev
.
#
Example: PUT RequestIn curl terms, this is equivalent to:
#
Example DELETE requestIn curl terms, this is equivalent to:
#
URL ParametersURL parameters are used to exchange small but meaningful pieces of information between web pages. For example, consider the URL https://req.dothttp.dev?page=3&query=ram
, where page=3&query=ram
are the URL parameters.
Dothttp provides a flexible way to define URL parameters using the following syntax:
With this syntax, you can easily comment out specific parameters, making it developer-friendly.
#
Example 1In curl terms, the request is:
#
Example 2 (Dealing with Spaces and Special Characters)In curl terms, the request is:
#
HTTP HeadersHTTP headers convey essential information about a request or response, as well as the data transmitted in the message body. The syntax for specifying headers is as follows: key: value
.
#
ExampleIn this example, the request sets the content-type
header to application/json
.
#
Request PayloadThe request payload is the final part of a request and typically contains data that cannot be passed in the URL. While not all requests have payloads, POST and PUT methods commonly do.
Dothttp supports various payload formats, including text, JSON, URL-encoded, and multipart.
#
Text PayloadText payloads are specified with the syntax: data("this is payload")
. Text payloads can span multiple lines without the need for escapes. Single and double quotes are also supported. To include double quotes within a payload, triple quotes can be used.
#
Example 1: Text PayloadIn curl terms, the request is:
#
Example 2: Text Payload with QuotesTo handle payloads containing quotes, Dothttp offers the flexibility of triple-quoted strings, inspired by Python.
#
JSON PayloadJSON (JavaScript Object Notation) payloads are widely used for data transfer in requests. The syntax for specifying JSON payloads is: json({"key": "value"})
. Using a JSON payload sets the content-type
to application/json
by default, which can be overridden if necessary.
#
Example 3: JSON Payload#
URL-Encoded PayloadURL-encoded payloads are commonly used in web requests when the content-type is not specified. The syntax for URL-encoded payloads is the same as for JSON payloads. Using URL-encoded payloads sets the content-type
to application/x-www-form-urlencoded
by default, which can also be overridden.
#
Example 4: URL-Encoded PayloadIn curl terms, the request is equivalent to:
#
Multipart PayloadMultipart payloads are used when multiple files need to be uploaded in a single request. The syntax for specifying multipart payloads is as follows:
All file paths are verified, and if a file path is present, the file is sent in the request. Otherwise, the inline value is sent. Depending on the file extension, the content-type can be automatically set, although this can be overridden.
#
Example 1: Multipart Payload with a FileIn curl terms, the request is equivalent to:
#
Binary PayloadDothttp files support only Unicode format, which means that embedding binary data in a Dothttp file is not supported. To upload binary data, you can use the fileinput("file path")
syntax.
#
Example 1: Binary Payload#
CURL EquivalentDothttp provides a simple way to generate cURL commands for your requests. Here's an example of a basic cURL request generated from a Dothttp request:
#
Example 1: Basic cURL RequestFor more examples, consider exploring the Dothttp Playground.
#
OutputDothttp allows you to save the HTTP response directly to a file. To do this, simply append >> "<full file path>"
after your HTTP definition.
#
Example:#
Math expressionsdothttp can expand simple arthematic expressions in json if they are in braces in json.
#
Example:above is a simple example but it helps simplify reading/making requests