Skip to content

This folder offers examples of how to use api methods like get, post, put, and delete to check values, giving you a basic grasp of how they work. Additionally, you may find check and report API codes here.[In API document you can find source codes and all the url to check or practice any task]

Notifications You must be signed in to change notification settings

Sakif1997/API_Postman_Codechecking

Repository files navigation

Project Title

This folder offers examples of how to use api methods like get, post, put, and delete to check values, giving you a basic grasp of how they work. Additionally, you may find check and report API codes here.[In API document you can find source codes and all the url to check or practice any task]

Project tools

API Source Urls:

method:Get -Url: Base_Url/booking/id

Method:Post -Url: Base_Url/booking/

Method:Put -url: Base_Url/booking/id

Method:Delete -url: Base_Url/booking/id

Visualization

Check data in console: https://github.com/Sakif1997/API_Postman_Codechecking/assets/45315685/4bf72b71-8293-44eb-abb9-2c634107ecc4

Methods body code:

Body code: https://restful-booker.herokuapp.com/booking \

 -H 'Content-Type: application/json' \
 -d '{
   "firstname" : "Jim",
   "lastname" : "Brown",
   "totalprice" : 111,
   "depositpaid" : true,
   "bookingdates" : {
   	"checkin" : "2018-01-01",
   	"checkout" : "2019-01-01"
   },
   "additionalneeds" : "Breakfast"
}

pic1

Post: Base_Url/auth

Body code:

{
	"username": "admin",
	"password": "password123"
}

response code:

{
    "token": "f66dcf8247182b9"
}

pic2

Put: Base_Url/booking/id

set Header: -H 'Cookie: token=f66dcf8247182b9

pic3

Body code:

  -d '{
	"firstname" : "James",
	"lastname" : "Brown",
	"totalprice" : 111,
	"depositpaid" : true,
	"bookingdates" : {
    	"checkin" : "2018-01-01",
    	"checkout" : "2019-01-01"
	},
	"additionalneeds" : "Breakfast"
}

pic4

Assertion details

method Put : Base_Url/booking/bookingid

to generate date

Pre-request Script:

const moment =require ('moment');
const today = moment();
pm.environment.set("checkin",today.add(0, 'day').format("YYYY-MM-DD"));
pm.environment.set("checkout",today.add(15,'day').format("YYYY-MM-DD"));

![date pic5](https://user-images.githubusercontent.com/45315685/206578219-8d6a8409-a39f-49bd-a35c-feacc9b6b63b.PN

Body:

{
	"firstname" : "Sakif",
	"lastname" : "Abdullah",
	"totalprice" : 111,
	"depositpaid" : true,
	"bookingdates" : {
    	"checkin" : "{{checkin}}",
    	"checkout" : "{{checkout}}"
	},
	"additionalneeds" : "Breakfast"
}

pic6

to generate random name

Pre-request Script:

var fname= pm.variables.replaceIn("{{$randomUserName}}");
pm.environment.set("fname",fname);
var lname = pm.variables.replaceIn("{{$randomUserName}}");
pm.environment.set("lname",lname);

pic7

Body:

{
	"firstname" : "{{fname}}",
	"lastname" : "{{lname}}",
	"totalprice" : 111,
	"depositpaid" : true,
	"bookingdates" : {
    	"checkin" : "{{checkin}}",
    	"checkout" : "{{checkout}}"
	},
	"additionalneeds" : "Breakfast"
}

pic8

Environment setup variables:

pic9

test Stats code

test to check match with name , date and status code

var jsonData = pm.response.json();
var code = responseCode.code;

console.log(jsonData);
switch(code){
    case 200:
    pm.test("matched with 200", function(){
    })
    pm.test("first name check", function(){
        pm.expect(jsonData.firstname).to.eql(pm.environment.get("fname"));
    })
    pm.test("checkin matched",function(){
        pm.expect(jsonData.bookingdates.checkin).to.eql(pm.environment.get("checkin"));
    })
    break;
    case 201:
    pm.test("matched with 201", function(){
    })
    break;
    default:
    pm.test("stats code unmatched", function(){

    })

}

pic10 pic11 l3 l4

Report Generate:

Comand prompt: Run Command:

generat file without environment newman run “Path/CollectionName.json” -e Path/EnvironmentName.json Because of not setting environment we can see lots of error pic12

Now we gennerate file with environment file also newman run “Collection Link” -e “Path”/EnvironmentName.json pic13

html report Generate

only html:

newman run “Collection Link” -e EnvironmentName.json -r cli,html pic15 pic16 pic17

html with extra:

newman run “Collection Link” -e EnvironmentName.json -r cli,htmlextra pic14 l2

About

This folder offers examples of how to use api methods like get, post, put, and delete to check values, giving you a basic grasp of how they work. Additionally, you may find check and report API codes here.[In API document you can find source codes and all the url to check or practice any task]

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages