POSTMAN
Postman, It is a platform for building and using API.
We can manage a complete API lifecycle with postman.
A postman help us to do.
Developmenttesting
Management
For more information visit
Explore Postmana website which consist of sample dummpy API'S for the practice purpose visit Click Here
We can get a endpoint to use in postman
The common http methods are
GET To get the values
POST To create the values
PUT To update the values
DELETE To delete the Resources
PATCHTo update the particular field.
Note:Put will replace the resources, and patch will be used for particular field updates and we can give only required fields in the body instead of whole body fields.
You can visit the link for more information about HTTP methods Click Here
Collections
It is a Group of API requests
variables
Variables are key value pairs or elements that can store different values.
we can reuse the value at Multiple locations if required.Change can be done at a single place.
Advantagewe can store URLS or etc in varaibles and we can use this variable in double curly braces {{name of the variable}}. instead of using the lengthy values. And this method can be used when some values is repeatedly used at multiple places. We can extract out all common values and keep them at one place.
POSTMAN - GET and SET Variables with scripts
Below the request section we can see the tests section in that we can add scripts to set and get varaibales.
Pre-req Scripts executes before running the requests
testScripts executes after running the request.
Setting variables with scripts
Global level: pm.globals.set("name","zaheer");
collection level: pm.collectionVariables.set("name","zaheer");
Environment Level: pm.environment.set"name","zaheer");
local level: pm.variables.set("name","zaheer");
getting variables with scripts
global level: pm.globals.get("name");
or
console.log(pm.globals.get(name);
or
we can store it in variable and then we can call exaample:
let value = pm.globals.get(name);
console.log(value);
collection level: pm.collectionVariables.get("name");
environment level: pm.environment.get("name");
local level: pm.variables.get("name");
note:
Access a variable at any scope, including local, based on priority.
priority levels
local --> data --> environment --> collection --> global
to remove: pm.enviroment.unset("name");
Environments
Environment is a set of key value pairs.
we can use it to store variables which can be used in requests and body and scripts etc...
example:
we can store a request url in a enviroment variable and instead of URL we can use that variable
endpoint=localhost:9008/rest/api/
at the reqest body: http://{{endpoint}}/user.
scripts
When we open any request, We can see pre-request script.= we can create any sctipts and this scripts
will get executed before we run And we have the test section here also we can create the scripts and the
scripts get executed after the getting a response from the server.
Tests
Tests in Postman are JavaScript code that is executed after receiving response. We can add test scripts as at a request level, collection level and folder level.
debug
Debugging in the console. Every request sent by Postman is logged in the console, so you can view the detail of what happened when you sent a request. This means you can use the Postman Console to help debug your requests when an API isn't behaving as you expect.
example:
we can run and check the pre-request script
console.log("this is a log");
console.info("this is a info");
console.warn("this is warn");
console.error("this is a error");
Now, open console we can check it.
We can also get data from json file and csv files..
To get the data from CSV or Json file first we have to create a file and add a data in the file and save the file with CSV or Json Extension
Now to add this file first click on Collection then click on three dots on right top on that collection,then you will get the run collection option, select a request method Then you will get.an option like Select file option then you have to upload respected csv or json file And run.
Authorization
APIs use authorization to ensure that client requests access data securely. This can involve authenticating the sender of a request and confirming that they have permission to access or manipulate the relevant data. If you're building an API, you can choose from a variety of auth models. If you're integrating a third-party API, the required authorization will be specified by the API provider.
For more information
DocumentationClick Here
Additional information: Click Here