19
loading...
This website collects cookies to deliver better user experience
[...] a set of rules, conventions, and data structures that dictate how devices exchange data
across networks. In other words, network protocols can be equated to languages that two devices must understand
for seamless communication of information, regardless of their infrastructure and design disparities.
The Hypertext Transfer Protocol (HTTP) is an application layer protocol for distributed, collaborative, hypermedia
information systems.
[...] one of the main protocols of the Internet protocol suite. ... a connection between client and
server is established before data can be sent.
nc -k -l 8080
to listen to incoming connections to the port 8080 of my computer.curl
command.$ curl localhost:8080
GET / HTTP/1.1
Host: localhost:8080
User-Agent: curl/7.64.1
Accept: */*
GET
is often the default./
being the root. "What\r\n
.- the request was made to `localhost` which can be useful to know if the server acts as a gateway or proxy;
- the request was sent by the `curl` program;
- the client would accept anything as a response;
HTTP/1.1 204 No Content
$ curl localhost:8080/ping
GET
request to /ping
. I will simply respond with a short message but this time,HTTP/1.1 200 OK
Content-Length: 4
Content-Type: text/plain
pong
Content-Length
header will warn the client to expect 4 bytes of data; the Content-Type
headers will inform thatcurl localhost:8080/users -H "Content-Length: 23" -H "Content-Type: application/json" -d "{\"fullName\":\"John Doe\"}"
POST /users HTTP/1.1
Host: localhost:8080
User-Agent: curl/7.64.1
Accept: */*
Content-Type: application/json
Content-Length: 23
{"fullName":"John Doe"}
POST
request to the /users
resource. The Content-Type
is application/json
, and the server should expect 23 bytes. After an empty line, we can read the JSON.HTTP/1.1 201 Created
Location: localhost:8080/users/1
Content-Length: 0
201
which means that it created the resource. Location
header. Finally, the response