HTTP-based APIs integrate easily with RESTful web services. There are many ways to use HTTP methods to consume and update and retrieve these API data.
HTTP API methods and understand how to use them appropriately on resources
Method 1: GET
The most common HTTP method is GET, which returns a representational view of a resource's contents and data. GET should be used in read-only mode, which keeps the data safe, You should get the same results no matter how many times you use this method, unless it is modified by another client in the interim.
Method 2: POST
Post request used to create resource (Record ) in server, While creating record we have to pass Body data Parameters(key, values) to create the Record as JSON, Form formats are supported.
While submitting the data we have to update Header tab content type with application/JSON.
After create new record by using browser you will received updated data. By default Browsers using HTTP Protocol with GET method to retrieve data from service.
Method 3: PATCH
PATCH is another HTTP method used to update resources. As opposed to replacing resources, like the PUT method does, PATCH only modifies resource contents. As a general rule, these modifications worked based on Key.
While submitting the data we have to update Header tab content type with application/JSON.
Patch update the record based on Id, after update you will find latest records by refresh your browser.
We have create additional record 4 for other operations in above list.
Method 5: DELETE
The last HTTP method DELETE. When a DELETE method targets a single resource, that resource is removed entirely(Hard Delete). we have to pass based on Key ID (4).
Delete Method will delete the 4th record based on Key. after we can refresh browser data.
Authentication
Authentication tab help to protect the API data using different security ways.
Basic Authentication is a method of securing HTTP requests through a special header:
let’s send a GET request to a Basic Auth-secured endpoint and expect an Unauthorized status for the response:
Now, let’s add the credentials. To do this, we simply go to the “Authorization” tab and select “Basic Auth” as the authorization type. After that, we insert the username and password and we’re all set:
2) Authorization: Basic <credentials>
To generate the credentials token, we need to write the username and password, joined by the semicolon character. After that, we need to encode the resulting string with Base64.
Let’s assume the username is “admin” and the password is “baeldung“. First, we’ll create the credentials string, which will be “admin:baeldung“. Then, we’ll encode it with Base64, add the “Basic” keyword, and set it as the header’s value:
HTTP provides a framework for controlling access to protected resources. HTTP authentication is performed by sending authentication credentials in the authorization header to access the protected resource. Bearer authentication (also called token authentication) is one of the HTTP authentication schemes that grant access to the bearer of this token. Bearer token authentication is done by sending a security token with every HTTP request we make to the server. You can do bearer authentication with any programming language.
Bearer Token Authentication Syntax
Authorization: Bearer {token}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
3 | |
3 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 |