Skip to main content

Request basics

Method#

dothttp 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 request#

PUT https://httpbin.org/put

try in browser here

or in curl terms curl -X PUT https://httpbin.org/put

example delete request#

DELETE https://httpbin.org/delete

try in browser here

or in curl terms curl -X DELETE https://httpbin.org/delete

URL params#

Passing 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

https://req.dothttp.dev
? page = 3
? query = ram

with above syntax, one can always comment any param and make requests. (dev friendly)

example 1#

GET https://httpbin.org/delete
? key1 = value2
? key2 = value2
? key3 = "value2 with spaces"
? key4 = 'value2 with single quotes'
[try in browser here](https://cedric05.github.io/dothttp-playground/#eJxzdw1RyCgpKSi20tcH0UmZeXr5Ren6Kak5qSWpXPYK2amVhgq2CmWJOaWpRhC+ERrfGMhXgggolGeWZCgUFyQmpxYrQWRNgLLqKLKZeek5qQqFpfklqcXqAJUcKes=)

or in curl terms curl -X GET 'https://httpbin.org/delete?key1=value2&key2=value2'

example 2#

example with spaces or special charectors

GET https://httpbin.org/delete
? age= 40
? name = "john don"

try in browser here

or in curl terms curl -X GET 'https://httpbin.org/delete?age=40&name=john+don'

Headers#

HTTP header fields provide required information about the request or response, or about the object sent in the message body.

Syntax: key: value

Example#

GET https://req.dothttp.dev
content-type: application/json
data("{
}")

above request sets content-type to application/json.

Payload#

It 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 payload#

POST https://httpbin.org/post
? key1 = value2
? key2 = value2
data(
"this is text"
// has a comment in between
" payload"
)

try in browser here

curl request for better understanding curl -X POST -d 'this is text payload' 'https://httpbin.org/post?key1=value2&key2=value2'

example 2: text payload#

In case of payload containing quotes its hard to add escapes. dothttp gives user flexibilty of triple quote strings (inspired from python).

POST https://httpbin.org/post
? key1 = value2
? key2 = value2
text(
"""this "is" text"""
// has a comment in between
""" pay "ram" load"""
; // break
'text/plain' // content-type
)

try in browser here

Json payload#

Json(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#

POST https://httpbin.org/post
json({
"name": "john don",
"age" : 20
})

try in browser here

UrlEncode#

by 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: urlencode#

POST https://httpbin.org/post
urlencoded({
"name": "john",
"age" : 20,
"lastname": 'doe',
// single quotes
})

try in browser here

in curl terms

curl -X POST \
-H 'Content-Length: 31' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'name=john&age=20.0&lastname=doe' \
https://httpbin.org/post

Multipart#

This method of payload is used incase of multiple files needed to be uploaded in single request.

Syntax:

multipart(
"name of file"< "file path",
"name of file2"< "filepath2",
"name"< "in line value",
)

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 file#

POST https://req.dothttp.dev
multipart(
'name'< 'value',
'name2'< 'test.md',
'name3'< '{"jsondata" : "jsonvalue"}' ; 'application/json'
)

try in browser here

curl mirror of above request

curl -X POST \
--form name=value \
--form 'name2=@test.md' \
--form 'name3={"jsondata" : "jsonvalue"}' \
https://req.dothttp.dev/

Binary#

http 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#

POST https://req.dothttp.dev
fileinput('C:\Users\john\documents\movie.mkv')
// or
// < 'C:\Users\john\documents\movie.mkv'

curl#

example 1:#

basic curl

curl -X POST https://req.dothttp.dev
--header "content-type: text/plain"
data("hai")

try in browser


Also checkout graphql example