API Testing HTTP 9methods 1672295716
API Testing HTTP 9methods 1672295716
9 HTTP
Methods
Stay ahead of the
game with these
essential HTTP
methods!
swipe
brijpandeyji
HTTP Protocol
HTTP stands for Hyper Text
Transfer Protocol. Communication
between client and web servers is
done by sending HTTP Requests
and receiving HTTP Responses.
swipe
brijpandeyji
HTTP Request
Structure
Every HTTP request should
have a URL or URI address
(Highlighted in purple)
and a method.
Example URI
http://api.example.com/products?
name=laptop&available=true
The format of a request message includes
A request-lin
Zero or more header field(s) followed by
CRLF (Carriage Return, Line Feed
An empty lin
A message-body (optional)
swipe
brijpandeyji
HTTP Methods
in REST
REST
It is a set of
REpresentational
State Transfer
architectural principles
for designing web
services.
Web services based on REST Architecture are
known as RESTful web services.
swipe
brijpandeyji
Categories of
HTTP Methods You can divide HTTP
methods into two main
categories
Safe HTTP Method
Idempotent Methods
Safe HTTP Methods
It doesn’t change data on the
server. It always returns the
same response, no matter how Example - GET, HEAD
many times it gets called.
Idempotent Methods
It may change data on the
Example - GET,
HEAD, PUT, DELETE, server. It always returns the
TRACE same response, no matter how
many times it gets called.
All safe methods are also idempotent, but not all idempotent
methods are safe.
swipe
brijpandeyji
swipe
brijpandeyji
GET Method
GET /api/employees/{employee-id}
Returns a specific employee by employee id.
GET /api/employees
Returns a list of all employees.
swipe
brijpandeyji
swipe
brijpandeyji
POST Method
POST /api/employees/department
Creates a department resource.
POST /api/employees/232/
department/114/department-items
Creates a department item using the employee id
and department id.
swipe
brijpandeyji
Testing a POST
Endpoint
Since the POST method creates
data, we must be cautious about
changing the data. Testing all
the POST methods in APIs is
highly recommended.
Here are some suggestions that we
can do for testing APIs with POST
methods
swipe
brijpandeyji
PUT Method
PUT /api/employees/123
Update employee by employee id
If it applies to a collection of
resources, it replaces the whole
collection, so be careful using it. The
server will return the 200 or 204 The PUT method is
status codes after updating. idempotent but not safe.
swipe
brijpandeyji
swipe
brijpandeyji
PATCH Method
PATCH /api/employees/123
“name” : “Brij”
}
Updates name for employee id 123.
swipe
brijpandeyji
swipe
brijpandeyji
DELETE Method
DELETE /api/employees/235
Delete employee by employee id.
swipe
brijpandeyji
Testing a DELETE
Endpoint
When it comes to deleting
something on the server,
we should be cautious. We
are deleting data, and it is Then perform the
critical. following actions
swipe
brijpandeyji
HEAD Method
The HEAD method is similar to
the GET method. But it doesn’t
have any response body, so if it
mistakenly returns the response
body, it must be ignored.
Example
HEAD /api/employees
Similar to GET, but it does not return the list of
emloyees.
swipe
brijpandeyji
Testing a HEAD
Endpoint
One of the advantages of
the HEAD method is that we
can test the server if it is
available and accessible as
The API can be long as the API supports it.
tested as follows
swipe
brijpandeyji
OPTIONS Method
This method is used to get
information about the possible
communication options
(permitted HTTP methods) for
the given URL or an asterisk to
refer to the entire server.
Example
OPTIONS /api/main.html/1.1
Returns permitted HTTP method in this URL
OPTIONS * HTTP/1.1
Returns all permitted methods
swipe
brijpandeyji
Testing an OPTIONS
Endpoint
Depending on whether the
server supports the
OPTIONS method, we can
test the server for the
To try it, consider the times of FATAL failure with
following the OPTIONS method.
swipe
brijpandeyji
TRACE Method
The TRACE method is for diagnosis
purposes. It creates a loop-back
test with the same request body
that the client sent to the server
before, and the successful response
code is 200 OK.
Example
TRACE /api/main.html
Responds the exact request that client sent.
swipe
brijpandeyji
swipe
brijpandeyji
CONNECT Method
The CONNECT method is for
making end-to-end
connections between a client
and a server. It makes a two-
way connection like a tunnel
between them.
Example
These are the 9 HTTP methods, their uses and a guide on how to
test them. Hope you learned about them in detail.
swipe
brijpandeyji
brijpandeyji
Follow Me On
LinkedIn
https://www.linkedin.com/in/brijpandeyji/