Request basics
#
Methoddothttp supports GET
, POST
, OPTIONS
, DELETE
, CONNECT
, PUT
, HEAD
, TRACE
, PATCH
, COPY
, LINK
, UNLINK
, PURGE
, LOCK
, UNLOCK
, PROPFIND
, VIEW
syntax is
<METHOD> <URL>
for example GET https://req.dothttp.dev
will make a GET
request to https://req.dothttp.dev
#
example put requestor in curl terms
curl -X PUT https://httpbin.org/put
#
example delete requestor in curl terms
curl -X DELETE https://httpbin.org/delete
#
URL paramsPassing URL parameters is a way to exchange small and meaningful information between pages on a website.
for example
https://req.dothttp.dev?page=3&query=ram
In here page=3&query=ram
is the url params.
Dothttp gives to fesibility to define params like
with above syntax, one can always comment any param and make requests. (dev friendly)
#
example 1or in curl terms
curl -X GET 'https://httpbin.org/delete?key1=value2&key2=value2'
#
example 2example with spaces or special charectors
or in curl terms
curl -X GET 'https://httpbin.org/delete?age=40&name=john+don'
#
HeadersHTTP header fields provide required information about the request or response, or about the object sent in the message body.
Syntax: key: value
#
Exampleabove request sets content-type
to application/json
.
#
PayloadIt is last part of a request is the body/payload. Not all requests will have payload. useually post & put methods have payloads. payload/body consists of data which cannot be passed in url.
With dothttp users can define payload in text format, json format, urlencode, multipart format
#
Text Payload:Syntax:
data("this is payload")
In here this is paylaod
is payload sent to request. it accepts mulitiline with having to escapes.
Single quote or double quote is also supported. In case of escapping double quote, one could use triple quotes like
""" 'this is "example"'"""
--> has quotes
#
Breaks:dothttp provides text breaks like data("string" "join")
converts to data("stringjoin")
using text breaks, dev can comment that specific key (dev friendly)
#
example 1: text payloadcurl request for better understanding
curl -X POST -d 'this is text payload' 'https://httpbin.org/post?key1=value2&key2=value2'
#
example 2: text payloadIn case of payload containing quotes its hard to add escapes. dothttp gives user flexibilty of triple quote strings (inspired from python).
#
Json payloadJson(javascript object notation) payload is one of the most used request transfer format.
Syntax:
json({"key": "value"})
Using json payload will set content-type
to application/json
by default (one can always override).
#
example 3: json payload#
UrlEncodeby default most browsers use this method by default (if content-type is not specified). usage is same as json payload
Syntax: urlencoded({"key":"value"})
using urlencoded payload will set content-type
to application/x-www-form-urlencoded
(can be overriden)
#
example 4: urlencodein curl terms
#
MultipartThis method of payload is used incase of multiple files needed to be uploaded in single request.
Syntax:
All file paths from above are verfied, if file path is present it will be sent, otherwise, inline value is sent in the request.
according to file extension, content-type of that file can be set. (can be overriden like this ('name', 'filepath', 'application/json')
)
#
example 1: with filecurl mirror of above request
#
Binaryhttp files will only support unicode format. As embedding binary data in http file is not supported, http provides upload file(can be binary or non binary) with this.
Syntax:
fileinput("path of file")
#
example 1: with file#
curl#
example 1:basic curl
Also checkout graphql example