Postman API Crash Course for Beginners [2020] - Learn Postman in 1 hour

Creating a Mock Server with Hard-Coded Responses

=====================================================

In this guide, we will cover the basics of creating a mock server using hard-coded responses. This is a simple way to test and develop APIs without relying on external services.

First, let's create a mock server response. We will use JSON data as an example.

JSON Response

-------------

Let's assume we want to create a mock server that responds with the following JSON data when requested:

```json

{

"name": "Erin",

"id": 1

}

```

To achieve this, we need to create a hard-coded response. Here is an example of how you can do it:

```python

import json

# Create a dictionary to store the mock server data

mock_server_data = {

"/users": {

"name": "Erin",

"id": 1,

"headers": {

"Content-Type": "application/json"

}

}

}

def get_users():

return mock_server_data["/users"]

# Run the server and test it

print(get_users())

```

This code creates a dictionary to store the mock server data, including the JSON response. The `get_users()` function returns the stored data.

Running the Server

-----------------

To run the server, we simply need to execute the `get_users()` function. When we do this, we get the following output:

```json

{

"name": "Erin",

"id": 1,

"headers": {

"Content-Type": "application/json"

}

}

```

This is the exact JSON response we specified earlier.

Handling Requests and Responses

-----------------------------

When a request is made to the mock server, we need to handle it accordingly. In this case, our mock server only responds with a single endpoint `/users`.

```python

# Create a URL to test the server

url = "/users"

# Run the server and test it

import requests

response = requests.get(url)

print(response.json())

```

When we run this code, we get the same JSON response as before.

Adding Headers

---------------

In our mock server example, we included headers in the response. However, we don't necessarily need all of them. Let's modify our example to include only the required headers:

```python

import json

# Create a dictionary to store the mock server data

mock_server_data = {

"/users": {

"name": "Cause II",

"id": -1,

"headers": {

"Content-Type": "application/json"

}

}

}

def get_users():

return mock_server_data["/users"]

# Run the server and test it

print(get_users())

```

When we run this code, we get a JSON response with only the required headers:

```json

{

"name": "Cause II",

"id": -1,

"headers": {

"Content-Type": "application/json"

}

}

```

Using Mock Servers for API Development

----------------------------------------

Mock servers are an essential tool for API development. They allow you to test and develop APIs without relying on external services.

Here's an example of how we can use our mock server:

```python

# Create a URL to test the server

url = "/users"

# Run the server and test it

import requests

response = requests.get(url)

print(response.json())

```

In this example, we create a URL to test the server and run it using the `requests` library. The mock server responds with the expected JSON data.

Tips and Best Practices

-------------------------

When creating a mock server, here are some tips and best practices to keep in mind:

* **Use hard-coded responses**: Mock servers use hard-coded responses by default.

* **Handle requests and responses**: When handling requests and responses, make sure to test all possible scenarios.

* **Include required headers**: Include only the required headers when creating a mock server response.

Conclusion

----------

In this guide, we covered the basics of creating a mock server using hard-coded responses. We also discussed how to handle requests and responses, including adding headers. By following these tips and best practices, you can create an effective mock server for API development.

"WEBVTTKind: captionsLanguage: enhey what's up you guys so welcome to the postman crash course what post been super useful it's one of the greatest tools you can use if you're working with api's at all and if you want to be serious in the software industry you need to know what api's are and how to use them so this tool will save you so much time all right we're gonna go over all the basics of postman we're gonna be going over how to use it all the functionality the whole UI like what its uses are and do a few examples and go through pretty much everything is it's pretty exhaustive but not everything but I mean it'll it'll be more than enough to get you started so we're gonna be going over how to create mock servers how to use variables and how to send requests all different kind of HTTP requests to any any of server or web server you can think of any website getting all your responses back all the analytics of it all of the data and all the statistics that you get from it this is a bunch of stuff it might seem kind of wordy now but when we get into it you'll see and it'll be pretty great so let's get started hey guys so welcome to the video before we get started though Before we jump into it I want to tell you that we have an epic free three-part master class it teaches you how to go from being a complete beginner and programming not knowing anything if you've never written a single line of code and the steps you can take to become a six-figure freelancer or a software developer so if you want to learn how to go from there to there click the link in the description down below it should be down there just gonna pop in your email address in your name and we'll send you an email to the login page for that and you can access it completely for free and it ends with a an exclusive webinar if you want to check that out too after the three parts so if I guess it's kind of like a four part masterclass but I definitely check it out alright it'll it's just a lot of free value and just we want to offer that to you so check it out all right you guys so let's start it with be posting a crash course alright so just a few prerequisites before you get started to understand how to use post pin and everything I'm gonna go over in this crash course you're going to need to know about what api's are about what rest api's are what web frameworks web servers and web clients are and stuff like that a lot of like online coding things and what hTML is and JSON and XML and I'll be familiar with all these terms in order to be able to follow along because you need to understand all this stuff to even use postman to begin with so if you don't know that then go back and learn how to do that first and then come back to this I will be explaining a little bit as we go just to like jog your memory so if you kind of know what those are and I mentioned things and you will be ok and things will come back to memory but if you have no idea what those things are then this crash course is not for you you should probably close out and go learn those things first start with a start with HTML and some other simple web stuff and go up the frameworks and and all that stuff and then you'll be ready for actually testing API stuff Oh an HTTP request and stuff as well that's very important to know that's what API is are based on but besides all those prerequisite stuff let's just get started okay so postman so postman in a sentence postman is a tool that you can use to work with api's all right so it basically allows you to test api's build api's and like create mock api's like servers like mock servers or mock clients and whatever so you can test them so while you're developing let's say you're developing a server or something then you can test it with this tool to make sure everything's working properly and vice versa so if you have a client then you could create a mock server or I mean if you're creating if you're trying to program a server then you can use postman as a mock client by sending requests to it like HTTP requests to it and whatnot but that's just a little overview of what it is let's just get started now so we're gonna want to download it first um you can either use the native app or the Chrome extension but I realized that the Chrome extension is deprecated as a saying right here but yeah let's just go to the web like here we go so this is postman it's just a plication we can use and we're gonna get into it very soon all right use cookies got it and pretty much what you need to do is just download it first okay so click download the app and yep just download it for whatever operating system using I use it for I'm using it from Mac right now and I already downloaded it but yeah so after you download it and you create an account and all that then we can get started with postman okay so go do that first I'm gonna continue on because I already have it downloaded and I'm gonna open up the postman app right now all right so I have a postman over here open it up and get this started loading awesome so it's loaded up perfect let's get this on a separate desktop cool so now I can go between my browser here my chrome and my postman so when you open it up you should probably see something like this or something similar you can just close out of this we're just gonna go straight to the UI I want to show you all the basics first now that we have it downloaded so I just want to go over all the UI and what all the buttons do when everything means and kind of just give you a tour of postman before we get into anything advanced all right so this is kinda like the basics like the basics crash course portion of the entire crash course all right so this is postman we are in postman and like I said it's just a tool that allows us to work with api's we can send requests we can crate mock servers and yada yada here we have all of the different requests we can do so we can basically send any HTTP request I'm here get and post are the two most common ones but of course you can use put and delete and all these other ones that we use occasionally but mainly just get in post alright and then when you are wanting to test an API then you can just use things here so let's just give a simple example all right so let's just say we want to test a this so we just want to get Emma's on comm you hit send then it will it there we go it grabs the the code the HTML code back from when we type in Amazon a common tool browser we get all the HTML code back and we can actually hit preview here and you can actually see that actual web site so my postman is is just a way a tool that gives you a lot of like leverage in different ways to change parameters and whatnot to work with api's and web servers and all this stuff okay we're not gonna be using Amazon the con when you season this because everybody's familiar with the webpage and then they understand how this is working so if we use a get request on the website then boom we get it right back alright but we're not gonna be using this anymore that was just for demonstration purposes so now let's actually use an example and I'll explain what everything is as we go okay so let's just do a get request first okay so let's um I have this cool JSON place all the website right here which allows us to it's a free open API where you can go into it and you get JSON back it's just that's why it's called JSON placeholder but we're gonna be using that right now at home for these basics let's just start that so yeah you can you can choose your type of request here we're just gonna do a get request and then when you hit Send it'll actually send it and get it back just like we did with Amazon so let's do that first and we'll hit send and as you can see we get our JSON back okay so if I actually pop this into chrome as well we would get the same exact thing just like we didn't post me and we just get some JSON back alright so JSON file if you don't know that is then this will make sense but this is JSON data and we're getting all this back alright just like we are in postman but here we have all the different options here to view it so we have pretty which is cool because you can actually collapse the JSON data or if it's XML data or whatnot well you could you can view the raw data which is just a raw string with formatting the preview which is what it would look like in your browser that's why when we went to amazon.com we actually saw the actual thing is they just HTML code because this is what it looked like in your browser and chrome it's auto formatted though but I mean that's just like extra fancy thing that chrome does and most browsers do but it's supposed to look like just like this just a raw string okay and visualize beta this I don't know what that is it's new I haven't checked it out too much but so if we are getting JSON data back then this will automatically go to JSON but of course whenever we are using a get request then we can have all different kinds of data coming back so whether it's XML or HTML just like we did when requesting up a webpage or text in general or whatever also when we are sending a get request then you can actually set your query parameters here so this is your query string like if you want to say like okay parameters like something like user ID oops user ID equals six like if you're gonna have that in the URL when you're calling an API then you can actually see that it auto cottle fills it out first here but likewise we can also do something like this right like hello this is a tight tool okay and it'll auto fill it all out for us and makes it very easy to construct these things so you have to type it from scratch so let's just get rid of that but yeah basically you can write our key value pairs here for any query string parameters and you can also set your headers and your body here okay so body is more important when you're actually doing post requests right but if you want to set your headers like content type or whatnot then you can actually you can actually specify these here okay or anything any other headers that aren't done by default then you can add them in here and it should actually autocomplete I think yup so like if you have like content type or like content length or something or whatever then you can just pop that in and then yeah that won't be auto generate for you you can also toggle these on or off so if it's on then it'll be it'll it'll be used but if it's ticked off then it's as if it wasn't even there to begin with but it's just nice to have it there because this is a tool so you want to make it easy to test api's and all that so let's go back Oh another thing I want to point out is you can actually um save so like I have this get request here right and I have like a bunch of different query parameters and different headers and bodies and everything like set up in a certain way and perhaps I want to keep testing it over and over again and I want to save it then you can actually save it here by using this button okay you can save this request but another thing is that there's a history of everything you actually sent so we sent to get requests already you can see the amazon com1 and then the one that I just sent so these will always be here and you can click on them and it'll actually take you like oh it'll open up another tab for you another tab for you and allow you to look at the requests that you sent okay so that's nice if you want to go back in your history like keeps everything there of course you can clear it all but yeah let's continue Oh another thing I'd mention whenever you are doing a when you send our HTTP requests then it'll get you the status code back here it also tell you how much time it took to do the request with all the stats there you can see the DNS lookup and all that stuff you know what if you actually know what all that means and also the size of the returning file the response file okay and then you can also save responses here but yeah I think you can also when you send you can actually send in downloads instead of just sending the request whenever you get the response you can actually download this entire file separately okay but that's only if one if you only want to download it but I think that is pretty much most of it for the get I think did I go over this headers oh this is the headers that we get back in the response so we'll have the date that the response was sent down the content type of course its application slash JSON and the reason UTF um utf-8 the char set blah blah blah and like all this other stuff I don't know what all of this means but I mean these are all the headers that we got from our JSON data which is very clearly JSON data okay and yeah I think that's pretty much it forget let's for get requests let's now try post requests so I believe in this open API what we can do here is they actually have an open API where you can put posts so now we can test post requests and we can send those out to this to this URL here and actually test post requests now so let's just turn on post request they're real as you can see the other get requests popped up here when I when I call it again but now let's do post okay so if we go into posts of course we have our query parameters and whatnot so let's just try this sending a post out as you can see here they are expecting a user ID or that isn't allowed key key and one of the key value pairs in on this API so let's just pop that into one of the query parameters okay let's just say user ID equals I don't know six or something or let's just put two whatever it doesn't really matter I don't know why I'm deciding changing it but we can put that and you whenever we send a post request then what we get back is actually the ID of the post entry that was just created okay so when we hit sent we're actually going to see that the ID comes back of 101 and you can see the post request pops up here but let's go back here let's go over some of the headers again you can set your headers of what kind of content you want to be putting there or ascending through and any other header few fields that you want and of course when we're doing a post request you actually need to specify what's in the body that's the most important part okay so within the body we can actually send nothing which would I guess do nothing it's just kind of useless maybe useful in some cases but form data of course is what we can do if you just want to send like JSON data up-and-down which is kind of what we're doing here by sending user ideas um user IDs and whatever titles or whatever it has I forget what was there me let me see V add our user IDs or regular IDs or title or body and all this stuff but when we're doing post of course we can send form data we can send form URL encoded data or raw data just straight string just straight string data or even binary data okay so if we wouldn't actually upload images then we could very easily just select an image to post to this here okay if our API allows it if whatever web server we are coding up or using or accessing if we're maybe using yeah yeah if we're coding our own web server and if it allows it that we can send it okay yeah I mean if we were sending a JPEG or something or something like that if we're sending a binary JPEG please like to the JPEG image here or PNG something then we could actually go here and change this it could be like image slash JPEG or whatnot and then that's how we could send a post across with an image and then of course we would have to select the image file here so you could just pick a image from your computer um but yeah all right well I think that pretty much sums up most of the basics here I think I went over pretty much all of the buttons of course he can get the headers again from your post response and test results we'll go over that later maybe and what else did happen I seen collections collections are just collections of different requests pretty much that you can put together you can like create them and just kind of keep them organized if you want or you can just like do test one by one like we were here um this gets a little bit more advanced maybe we'll do that later but I think I've gone over most of the basics here so you guys shouldn't know how to send getting post requests and how to set all of your different parameters and whatnot whether it be quarry string parameters or headers or your body and your body types and all these different things and you should be able to see how like how to see what's coming back and whatnot and it's just very useful if you are working with api's and you're trying to like test if you're like coding up a client's side thing and you want to have a mock server or to like compare if things are working correctly then you can use postman to like create create dummy requests or like mimic some of the requests and see if what's getting coming back is what you're expecting to come back and so forth basically it just allows you to fake servers and fake clients and to make sure it's working correctly just so you can test your API so whether you're building it or testing it or or just using an API but yeah that covers all the basics and I will see you in a few seconds going over whatever we go over next all right you guys should be a few seconds later for you but now I just want to go over really quick about bulk editing query search query string parameters and creating new requests and collections credit collections and saving requests to collections well it's still pretty basic but I just need to go over it a little bit more involved but that's I'm going over it now so let's say let's create or let's change it first let's let's just query amazon.com again I actually I'm gonna use this again amazon.com all right so we can preview it we can see that we have the webpage here and have the HTML code here but let's say we wanted to actually search something on Amazon okay so let's I believe on Amazon if you just put s that's the search URL so now it's getting ready for a search and then we just have to add into the query string parameter here um I believe it's K I don't know why it's called K but we can put anything we want in the value so if as you can see when we're typing it down here it's Auto completing the query string parameter so we're gonna say amazon.com search and the term search term we're gonna search for is iPhone so let's just hit Send and if we click on preview then you should actually see that iPhone was complete up on the arm in the search bar under all departments and I'll be can see a bunch of hyphens pop up there might be like another parameter here for departments like something might actually change what this is instead of like just all the parts you get to go to like technology or something I don't know I guess there's something something there that would make more sense for iPhone but yeah that's that and let's say we maybe have another one so maybe there actually is one I don't think this is actually true but like let's say if we had like Department we could be like all or something okay Department equals all and that could be like this now I want to show you bulk edit so if you go to bulk edit here on the right instead of having this nice interface using key value pairs you can actually click on bulk edit here and see everything you have as just a string and this is useful because you can just go in here and just copy and paste or just copy it and then you can actually go up here and click plus and you can actually type in amazon.com again oops comm / s and then down here go to bulk edit and then just paste this in here and go back and as you can see it's all auto completed so you can like copy request that way you can also just right click up here and duplicate the tabs but that's actually not a true copy sometimes like the names and stuff still get the names will always be the same or something like that so I don't like using that I always just create a on do one from scratch but let's just get rid of this one don't save it let's go back to this request that we had okay so search for iPhones let's turn off the bulk edit mode going back here so we have an iPhone search now let's talk about creating a collection and saving requests to collections all right so once we have a request here we have a get request on Amazon just searching for iPhones then we can click Save over here alright and it brings up this save request little window so in order to save your request you actually need to create a collection um it's kind of just like a folder for a bunch of requests I mentioned that a few minutes ago but let's just click create collections down here and let's just call it Amazon searches alright hit this little orange check sign and now it's selected if I click back on it you can see all your collections here and then this you can't save anymore but when I select Amazon searches I'm in here and now I'm able to save a time on services so the name of this request it's going to be Auto completed to whatever the URL is the query string but I actually just want to make it cleaner and say Amazon search and I'm just gonna say iPhone just like that okay you can put a description if you want but that's optional I just put hello sure why not and now we can just click save to Amazon searches all right so now we save this request you can see the name up here change to Amazon search iPhone and if I want to change the name then I can I find this little down arrow then you can see the description you can also edit the description down here you can even use markdown which is pretty cool save will collapse this back up so that's that and now now that we have our collection made if you I should click on collections over here on the on the left you can see that our Amazon surges collection was made and it says there's one request inside let's just click on it and as you can see there's Amazon search iPhone okay now let's just create a another one okay so let's actually use this well let's go to bulk edit and just copy all this oh not that much I mean you could actually just like type it in yourself but I got a bunch of these different parameters if you wanna copy over it's actually useful turn this off go to this plus sign create another one I'll let's just say it's Amazon calm slash s again go to the bulk edit paste it in go back cool and now I don't I don't want to search for iPhones anymore maybe I want to search for MacBook okay or just MacBook and now let's pop send sending the request waiting for the response down here go down to preview and as you can see now we have our search results for a MacBook and if we scroll down then there's a bunch of mac books available okay cool so now I'm gonna save this to alright and I'm just gonna go Amazon search and it's gonna be MacBook okay and no description this time okay and then we have it selected you can already see our our previous one iPhone was created down here you can see it faded out and we'll just hit save and boom there we go so that's how you save your searches okay so that way you have to keep typing from scratch every time you can close out of both of these so when you open up launchpad I mean on postman and this is oh yeah this is launch pad too you can go here and there's a bunch of other UI stuff but later later now we have our collections here so we have our history of course we can go through um you can delete all this stuff let's just delete these why not delete okay so they're gone forever but if you go to collections then they're still here I mean you can delete these two by hitting these buttons but now we have the ability to see these again so when you click on it they pop up see its italicized though so if I go to other one then they don't stay open but if I want to keep it open and then you just can hit Send and then see it'll it'll on italicize right now after I send it and then now when I select macbook then it just opens opens it up in another tab there we go so we have iPhone and MacBook and you guys get the idea okay well that wraps up creating collections and saving requests and using the bulk edit mode and I will see you guys in a few seconds again to go over whatever we go over next alright you guys so now we're gonna go over variables in postman so variables are exactly what they sound like they allow us to set variables and have those things change wherever those variables are so if you have some variables in this URL here like if you had something like a variable here or whatever slash variable one or something that we could actually set this variable somewhere else and then have it this be filled in with whatever the value of variable one is so there's actually two different ways we can do variables um there are path variables and then traditional we're not traditional path variables and then like real like global variables I'll go over to path variables first cuz it's very simple in straight-4 it's like a mini variable pretty much only for paths in the URL and then real variables are like variables that are like within postman that you can set variables like within the entire app so that whenever you change one of the variables then in every single request everywhere then that variable is change or something like that like they're very very powerful but let's go over the path of riyals first which is very simple this will make more sense as we get into it okay so we were using this nice API here let's just click this again send a get request to see what comes back and we get a bunch of stuff it's been a couple days from me so I might already gone over this I'm just kind of half refreshing myself and half reminding you if you're coming back or something but all right so we have this thing we have a bunch of posts here all right and if we could filter by perhaps if we use ID then we could like oops then we could filter it like that and it's send and then just get the one with all the user ID of one or the mean the ID of one and also if we did users then we also get a bunch of stuff here and we can again filter by the ID of one okay send that and boom we have just this one instead of all of them so now I want to point out that we are able to change the path here so users here we can actually change users to posts like we did before and if we hit send again and get the response back then we have a different post here so perhaps we wanted to go through all the posts and users that have this same ID doesn't really make sense logically but I mean this is just for demonstration purposes so as you can see this is the portion that's changing so if we wanted to create a path variable there's a little secret trick here it's kind of hidden and what you actually have to do is um get to the portion where you want to have as a path variable and delete it and then just put a coolant okay and then I'm gonna put path and as you can see if you look right down here like look great in this area when I type when I start typing this thing called path variables magically pops up okay Matt just magically pops up there and that's because we're able to set path variables okay so I'm just going to call this path 1 or path of r1 or whatever cool and down here is where I'm able to actually set users or posts or the value of the path variable so the way this is working is because this is preceded by a colon this is considered a path variable and path 401 so whatever this is is going to be filled in with whatever we type in here so user um this is going to be the same as what we just had oops users sorry there we go so we have a user with the ID of 1 and then same with posts send and it works as expected okay so this might seem a little bit clunky it kind of is I mean right now for this example like you wouldn't need to use it for this one but it's very useful if perhaps you have an API where you're working with you're accessing something like maybe you're accessing YouTube right you're accessing YouTube and you have like you want access like different comments on a video and every comment has an ID okay but you want to iterate through all of them or something like that then you could it could be very simple like um it might be like youtube.com or whatever yeah just pretend this is youtube.com and then you could have like or slash video 1 whatever it is slash um comment comments slash and then you could have like that I like the comment ID or something like that ok and then you would put in like ok comment ID and then from there then you could actually like put in the different numbers and send it and then change it and keep iterating and just keep going up and up and up or whatever you wanted to do like it's very useful for that and then of course you can have multiple ones so comment ID and then you could have like whatever else after that like comment ID - etc like you guys get the idea but let's go back to what we had before yeah we don't need this oh and the last thing I want to mention about these is in order for this to work this has to be part of the path path variable okay and you see part in the path up here in front after the domain with all the slashes and stuff it can't be part of the parameters okay so no you cannot if you wanted to go like okay path and then ID if you wanted to go ID here then as you can see it's getting changed here it's not actually popping up as another thing here so remember when I typed in path then imagine we popped up here right if I type another slash and then I typed in here and I typed an ID see how it pops up down here but if I type it in over here outside of the path and after the variables the query string parameters I mean the app yeah the the parameters after the question mark then it won't work okay it won't so we can't do it that way that's the whole point of these down here okay because you already have the parameters pretty much so this is actually two parts of it it's just as part is hidden this is how you change you can use um put variables in this URL on the left side of the question mark and this stuff up here the query parameter is how you use variables on the right side of the question mark okay and that is pretty much um path variables so let's get into variables next alright so now we're getting into true variables like real traditional variables home I recorded this whole segment then I got deleted which is kind of annoying so I'm starting over on that's why this looks as different all of a sudden but pretty much variables true variables allow us to pretty much put anything we want in here anywhere at all and to specify what the variable is so pretty much it is what it sounds like unlike path labels we're limited to only changing the path over here like per per parts of the path or query string parameters we're only able to change like parameters over here variables we can change anything we want and we can basically be a full freedom with it you can create variables at many different levels and postman so like one level is collections so if you myrrh we created this Amazon searches collection then we can actually set variables at that level that's what I'm gonna demonstrate first but you can also create it at the environment level or the global level and just explain what of environment is really quick we're actually will do that later let's just actually this videos can be better because I'm gonna go in a better order but so let's just create one at the collection level first alright so remember we had this collection that had two requests were searching for iPhones let's send that in and you can see the responses already there but we'll just send it again if it will hurry up bear with me guys there we go so iPhones and then also Mac books right I'm not gonna demonstrate this because it's already there it's exactly the same but let's say that in the collection we wanted to set a variable to find some similarity between these two so within these two requests we can tell that this part here amazon.com /s s is a short for search is the same in both so why don't we set that as a variable okay so let's just copy that and hit copy and then go over here to collections hit on this triple dot thing go down to edit and all now that we're in here in this collection there's like a little tab here called variables we go there and now we can specify a variable okay so let's just specify a variable called Amazon all right Amazon and then the value we're gonna give it is amazon.com slash s okay and it tells you the current value as well if it's changing over time but let's just hit update alright and now we can see if we go back here we go back to edit then the variables it should be there this little green dot telling us that there's stuff in there and we have Amazon so now that we have that the way we access a variable in postman is to use double curly braces just like that okay and as you can see it turned red to specify that to show that we're using a variable now and now we can I'll pop in the name of the variable which was just Amazon and this will actually autocomplete to amazon.com slash s as you can see if we hover over it that little um it actually tells you what the via the initial value of the variable was and then what the current one is and then also the scope so these variables only apply to this collection so if you use Amazon and anything within this collection then it'll autocomplete to that but any other collection or outside of it it will not okay so that's that let's hit send to just prove that it's still working I mean you guys can probably take my word for it you can test it yourself but I'm just showing proof reasons there you go that works and then again let's do the same thing but let's just copy and paste it should copy and paste the reason I mean you could you could argue that it this is also the same to the question mark and the K equals the search term in both which is true but I mean I don't think it's very it's not very good practice to just like do that because you don't want to like bridge the gap with the parameter question mark splitter thing here where the parameters start it just doesn't make very much sense like you have like maybe like a separate variable to keep the question mark there and then have like oh like a search term or something okay but let's just test to make sure this works as well get the get request for this one the Mac Book Search and as you can see it works as expected as well okay so this is pretty cool I mean you can have multiple variables of course in the collection and and whatnot but also there's a way you can slit global variables environment variables let's get into that now I'll show you global variables wifey let me explain environments first so we're actually gonna get into environments next right after this um in depth and how to create them and stuff but I'm just gonna explain what they are really quick so if we go up here this kind of like where your environments are this little rectangle here it says you can cite your environment there's no farm mines created we're gonna create one later but if you click on this little eye thing and then it says environment here and Global's okay so these are two other levels where you can create variables so we just created at the collection level which is like the lowest level or one of the lower levels and then now we're environment so an environment is just a set of variables that allow you to switch the context of your requests so that's pretty cool because we can set a bunch of variables with an environment and then whenever we were in that environment automatically everything um has those variables applied which is very cool so and then if variables of course just applies to all environments okay so this is like overarching no matter what and then environment so but we can switch our environment and pick one - how like a set of variables set so this is pretty cool like one example I just thought of is let's say you know how we're doing Amazon searches here maybe we have a we also want to search a bay or something okay and there have like two different collections or I mean yeah we're what two different sets of does happy clash there's two different sets of requests we have to do environments maybe we wanted to have like one Amazon search so or actually just like um I think I better explain it is if we wanted to have two environments like one Amazon and one eBay okay then we could have our request to be even simpler so instead of so this being amazon.com right we could just have it be like website okay or like shopping website or something like that okay and then have this as an environment variable and then whenever this changes I mean whatever we changed environments then like in the Amazon environment in the Amazon environment then the shopping website variable would be amazon.com and then the eBay environment this variable would actually change to something else so that these requests are like useful depending on are still useful depending on which environment we are so like let's say we want to also check a Bay for like Mac books and iPhones this is K for the search room for Amazon but it might be different for eBay but we're using variables you could just say okay search term you know something like that and but I mean this is always gonna be the same question mark and then equals always gonna be the same but this gives us a power here because now if we're in the Amazon environment we can just say shopping website is Amazon the comp search term is K I'll mean slash s2 right we need / s oops / s for Amazon but we could keep that we could include that in something or people like search whatever but the idea is that yeah you could you could use this same request for both Amazon and eBay to search for iPhones and Mac books just by hot swapping the environment if we had the environment set up correctly so that's pretty cool okay because yeah just if you guys still aren't we following then it might be like amazon.com / s and then search term equals iPhone but eBay might be like ebay.com / search term equals iPhone so the term here but it says K here and then um this will be / s and then it says s here but it says search here or something like that this isn't probably actually right but I mean that's just the idea of it okay so that is that let's put this back to Amazon alright because it's complaining that is an unresolved variable there we go and then make this okay and send it again last thing I want to talk about Oh Amazon typos bear see and that's actually a very good point um I was just about to explain that the issue with variables though is whenever you have a bunch of variables here suppose you have like five ten whatever variables in your query request string here then you can't actually see what's being sent okay because the variable is hiding what is here you don't have to keep opening like okay if you had like a collection variable and an environment variable and then a global variable or global variable is real quick I forgot to mention that let's go to global variables if you click on this little setting sign up here on the top right okay then you can go down here to Global's and you can actually set global variables so this is like things that make sense to be global so it could be like my name value is gonna be air in okay and then like there and you just hit save and then when you hit save it just automatically saves it blue global as you can see it's still there my name ahran and that pretty much just applies to everything every environment everything at all I can use this anywhere I want if I have if I type in my name it's just gonna autocomplete the arrant no matter what okay very simple and you can delete them by clicking on the X here that's global variables very straightforward but getting back to what I was saying but sometimes if you're trying to troubleshoot with variables and whatnot then it's very easy to make mistakes because you might have a bunch of variables and you can't actually see what's actually being sent I'm like me I just had a typo right but I might have not known that be like why is my request working what the heck oh this is so annoying I mean first all you can hover over it which is good because tell you it's an unresolved variable but also if you just want to see like the exact raw static request that you're getting on the response you're getting then you can use something called the postman console which is like a no-frills version of everything sending the requests and responses so we have our cool thing here with all the variables but if you go to the bottom left here the little thing a little icon when I hover it says postman console let's click on it and it'll open up a new window and pretty much what this does is it just shows us all of our quests so let's go back to postman and I'm using this variable here I'm searching for Mac books let's hit Send let's go back to this and as you can see now this little get request just popped up okay get amazon.com / s see how it auto fills out the variable for us and then it says search I mean then K equals Mac Book we can collapse it and then we can see the request headers everything in here absolutely everything the response headers and the whole response body but we can't see it because it needs to be larger anything larger than one megabyte can't be shown but that's okay because we can just go down here to raw or pretty and get the response string there if we want okay but that's just a nice little thing to allow us to troubleshoot if we're having issues with variables or using variables and we can't figure something out and you need to really like see at the low level exactly what's being sent and received um then we can go here to post on console okay if you don't this little icon down here on the left then you can go to view show postman console or use your little shortcut here um it might be different on Windows but yeah just looking like view or something or or or google it you can find the console Oh or whatever version of postmates using but that pretty much wraps up variables for you guys we're gonna get into environments next a little bit involved actually creating environments in blah blah blah and setting variables within dos all right you guys so now let's go over environment okay so I said earlier environment is just a set of variables and that's exactly what it is like literally it's just a set of key value pairs that we can turn on and have it applied to something to whatever right the I'm actually gonna do the example that I did the Amazon eBay we're actually gonna do it I mean we're gonna go through with it and um create a environment for Amazon and create Amazon I'm an environment for eBay and then be able to hots off between those two collection environments to run the same amount of requests the same series of quests the same collection of requests to search both websites based on the environment so on before we get into the environment though really quick let's go to a collection here I mean collections again I'm on my Amazon searches and then if I click this little arrow and and click run then I can actually run the entire collection okay which is just gonna run each of these one by one alright we have a bunch of different settings here I'm not gonna go over this right now let's just click run Amazon search collection and it's running it says little progress bar here 50% running one iteration no environment that's uh note that this is no environment here very important we're getting our responses back and it's almost done we're taking a little bit there we go and it's done so get all our results back run summary yada yada it's not we're not going over this right now but I just want to show you that you can run everything in a in a collection all the requests in a collection this is no environment so what we're actually going to do is we're going to create a collection of searches and then create different environments for depending on which environment we're running those searches in in our case it'll be Amazon eBay and then we can actually hot-swap those environments in and run the same requests with those different environments okay which is really cool because then we can create environments for maybe Google um shopping or any other searching shopping websites that all might exist so yeah let's let's start with just duplicating oops let's start with duplicating in this collection I don't want to get rid of it that's why so just go to duplicate cool here it is and now let's close both of these don't save and don't save whatever did it save those variables no it didn't that's cool though alright so let's go into here and now let's just change the name of this um to shopping website search cool and then oops actually searches okay cool and then here it'll just be we rename this to just iPhone so just iPhone this one's going to be just MacBook and then of course we can add more that we want whenever we want but we're just gonna do this and uh okay let's get started so um I think we should create the actually let's do this first let's just oh now I think we should create the new armor first let's go up here at the top left you can click this button and there's little window pops up environment we can click this or you can just click this little drop down menu and click environment here which is what we're gonna do so now the environment is just going to be Amazon Amazon okay and then for variables we can set all the variables one for this environment so what we're going to set is going to be I believe shop being website is think about I use before and then for us it'll just be Amazon calm cool and then also we're going to use search oh sorry actually don't need these in here silly me and then also we need search endpoint yep search endpoint and that will be just slash s and I guess we can put WWE don't need that screw it like that and then also search term and that will be K alright so as you can see we have amazon.com slash s and then we're gonna our parameters and it's going to be K and equals whatever it is and but then we have these nice variables here okay shopping website search endpoint and search term okay so let's just add all these all done here's our environment with the three things in there and now let's go back to here let's go to here and instead of Amazon we're going to use shopping website okay and then instead of search term I mean we're going to use search endpoint all right and then a set of K we're going to use search term all right and um yeah then iPhone stays because its host be iPhone so that is it let's send this it's probably not gonna work because we're not in the we don't have the environment set for it okay for this request which is okay but let's go and do the same thing for macbook so actually let's delete this one delete macbook and then just duplicate iphone duplicate and in here we will just rename this to macbook cool and then also we're going to just change this to macbook and that's pretty much it okay it's not gonna work again it's broken it didn't copy all this over all right copy that in just like that okay well I'd save this one I'd save on this one maybe that's why I didn't I'll duplicate correctly because I didn't save it alright so now that we have these two these two searches this is going to search for iPhones depending on any websites we have the website and then whatever search think we have to add on to it and then also the term that is required to search for an item on that website and we have the same thing for both which is cool but now now that we have this let's actually this collapse this let's actually set up an environment now that will arm well we already have the Amazon one set up so let's just run that okay so let's go to shopping website searches let's go to run okay and hopefully I typed in all of these variables correctly there's no typos let's go down to here so as you can see we have two searches to request your iPhone and MacBook with those variables in place and then if we just go down to environment and we select Amazon the one we just created um earlier and one iterations no delay you can set delays like between the searches I mean through the iterations like if you want to run on everything twice then you just put two iterations and then you could put like delays and whatnot but yeah let's just go there the main point was just environment you want to show you guys this and then when we run it you can actually see that the request that's actually being sent is amazon.com /s query parameter K equals iPhone okay and same thing amazon.com / s query search term equals Mac Book okay so everything's going correctly it's just a bit slow sorry this computer is not that powerful I should probably use the other one but it's not so bad alright cool so they both work correctly we got the green checkmarks and that was wearing the collection in with the Amazon environment so now let's create in ebay environment then we can see how we can use two different vironment for the same collection and run this collection over and over again depending on the environment we choose okay so let's go to here so new environment and actually I think if we just go to Amazon I think we can duplicate it is this duplicate or can we duplicate there we go duplicate perfect that makes it nice and easy it's not just going to here and instead of this we're gonna say eBay alright and then now now that we have all the same variables here now now I can't make any typos perfect we can actually change it so instead of amazon.com now we're going to have a bay comm of course all right update oops you better calm and then the search end point I believe for eBay I looked it up earlier the search end point is a little bit weird it's this ok it's not just /s like Amazon it's actually this alright and let's just pop those in there like that update and then last lastly the search term is also kind of funky it's ampersand underscore and kW whatever that means instead of just K but the point is that we're gonna put these in here like this update alright so now we have Amazon and eBay let's close out of here and now we have our commands here now if we go to this collection and we hit run and this time we can select eBay or Amazon and then run the file or run the collection then we can see that we are getting ebay.com / SC h / HTML and that one too and you can see that they both passed and it was it was filled out correctly because of the environment use but we were actually ran the same exact collection it's just with different environments okay so that's pretty simple like literally all environment is just a bunch of key value pairs let's go here again environment and you can just set them all and then you have a bunch of different vitamins and then you can you can like select these environments like if we're ho here in Amazon okay if you have this selected here well let's do a okay if we were in eBay and then um then we sent it let me go to preview then we can actually see that there was i phone searches in ebay here okay because we have it selected and same with macbook it is gonna behave the same exact way and there we go oh and I realized I didn't actually show swapping so really quick we had the eBay MacBook search here let's just run this again so running fresh and then all we need to do we see we have our macbook our macbook search results on ebay all we need to do is just hot swap to amazon the amazon environment and then running it again the same exact request we're just in a different environment and it'll load suddenly we are on amazon searching for macbook as well okay so that's the power of environments now we can you could add on like different technologies you could change to like oh technology website searches whatever and then have like iphones MacBooks i don't know i watches whatever Apple watches any anything else you want but yeah that's environment so you guys hey you guys so now we're gonna go over writing scripts and postman I've specifically pre request pre pre request scripts it's hard to say as you can see over here that I'm clicking on and I'm also tests you can write tests the difference between these two is we can both of them are scripting pretty much but pre request scripts will run before it runs the request and then tests run the tests both the response comes back so it's kind of like okay where we can edit the request here by um running scripts and then when the response comes back then we can run tests on the response to make sure um things are coming back as expected but right now I'm gonna go over just pre request scripts first um you can have this in many different levels you can write these at the collection level so it applies to like everything in a collection when you run a collection it'll run this script before every collection and every request and likewise with scripts I mean I'm like rise with tests that it'll it'll apply to all of the the entire collection that as you can see here I click on edit collection and there's also pre request scripts and eight um option here for collection so you can write it at the request level like I am right now per request or you can write the collection level and I believe you can even write it like other levels but we will just be focusing on this because it like if you understand one then you can apply it to all the different levels and it works just fine all right so let's let's go back to I'm in this collection right now with the environment we have the environment of Amazon and then we're running the the iPhone search term and let's just say I wanted to change some variables that's a very common thing to do in the strip's change some variables before we run the request okay so let's say we have like okay we have this whole thing here and we're searching for iPhones well I want to show you how maybe we could change that so like I mean obviously we can just go to the parameters and change this iPhone to Apple watch or something right manually right here but maybe we didn't want to do that maybe we want to like test it like on a different parameter or something like oh if if iPhone has no results blah blah blah or something or iPhone something and anything then you can just change it like on some parameter like basically you can you have full flexibility because you're just coding out here but I'm just gonna show you how you can get variables and set variables which is the most common thing you would do most basic thing you would do in pre request scripting okay so if you if we go to this upper end thing on the environments and then I click on Global's you remember that I set a global variable called my name and set it to my name Erin you know the current value is currently airing and this is all we're going to need I'm just gonna use this use this as demonstration purposes to show you how to do this so um we are in a pre request script for this request so what I want to draw your attention to is here on the right there are something called snippets a bunch of snippets here and pretty much what these do is they just allow us to it writes code for us automatically very easily so that we don't have to like code it all from scratch so as you can see we can get an environment variable we can get a global variable we can get a variable you can set all these variables we can clearing variables on all the stuff we can even send a request we can send a request within the script before we send this request and stuff like that as you can see like well it's going to this URL blah blah blah and then like just printing the stuff out to the console as when I clicked on it you saw that it auto complete which is pretty cool but we're just gonna use one just to show you you guys you can explore all of them yourself if you want but in this priam request script I'm just going to get a global variable okay well actually first let's comment that out this is a node GS I believe if I'm not mistaken so you probably need to know that to make you submit but not really because you can just use these snippets and kind of get it done and if you're not a program in general then you can kind of figure it out but let's just do console dot log first okay and let's just go hello world okay just to show you how this script will work we have this here and let me open my let me open a fresh postman console there we go and it's going and now it's empty but let's run this request okay go back here and as you can see hello world popped up in the console alright and before the request was sent you see how that works hello world was printed and then the get request was sent okay and then if we go back to postman we can see that yeah we look for iPhones and I was on cool now now um that we know how to print we printed hello world now I want to get I actually let me delete this if you guys forgot I want to get a global variable so I just click on this snippet and boom that's how I get a global variable remember I had the global variable of my name so it's this variable key every variable is a key value pair so what is the key of that variable well it was just my name like that okay now you can even see it autocompletes for you with the initial current and scope tells you global and then you just say my name and then we can actually print this out as well if we needed to okay so let's run this again go back to the console as you can see hello world printed out as normal but also Aaron printed out which is the global variable my name okay and then we sent the request because this is a pre request script so again we can do all these cool things you can also like like set variables within here cuz of course you can code you have full control over everything and go like this and then have variables in here and then you could like like check can be like if if my name equals Aron yada yada you know stuff like that or whatever however you want to type it all pretty much you can do anything you want in here I'm just showing you the the basics and then you're free to problem solved as you wish so that's how you can like set variables and whatnot and print them out in pre scripts um one more snippet I want to show you is actually setting so let's just set a global variable and now it says they're asking for the variable key so this is gonna be my name okay and the variable value I want to put it to my last name which is just Bernath alright so this is going to set so we have we're just gonna print hello world and then we're going to get my name which is gonna be Erin it's gonna print out and then actually let's close this so that doesn't get confusing let's open up a fresh one this is irrelevant I'm just showing you how to how to save a variable I'm going to delete that and then then we're gonna set it and then we're gonna do it and then we're gonna print it again alright just like that so right now the global variable is iron right there as you can see and the postman console is empty and let's hit Send on this get request wait for things that come in as you can see hello world popped up okay Erin and then Erin popped up because we printed it out and then we set the my name Google variable to Bernath and then printed the burneth variable the my name variable again which is verrat my last name and then it sent the get request okay and actually if we go up here to global variables we can see that the the value of the global variable is actually changed okay so that is pretty what you can do in pre request scripts I mean you're able to basically modify all of the variables like if you want to modify these environment variables instead of as we're in the Amazon environment variable right I mean we're in then we're in the Amazon environment right so we I could actually go in and get these variables out like Amazon calm and slash s and K and stuff and I'm going there and actually change those just by calling these things like get an environment variable PM stands for post mates in case you're wondering PM post mates dot blah blah blah or postman not post mates I guess I'm getting hungry and then set environment variable to same deal and then regular variables of course so that's kind of the general idea maybe like you wanted to be able to change the iPhone thing like I mentioned earlier like you like basically you're able to just use code to do whatever you want with the request so you have like full control over all of it okay so that's pure um request scripts um now we're gonna get into testing which is very similar alright so testing so writing test scripts like I said earlier is testing the response that we get back from a request okay so we are going to try that now so I found a different API here other one was giving me a little bit of trouble with it um but this one's cleaner and easier the JSON is is just cleaner so we're gonna use this one let me just run the command so you can see what it looks like it's HTTP rec rests which is probably request response NDP I've at slash users it's just like a dummy API that we can use there's some nice JSON here very similar to what you're using before but um yeah so now let's write a test let's just go straight here and just start reading it so this is the response we get back okay as you can see there's a bunch of different stats here like the status 201 okay and then time I took in all that stuff from the size of it but if you go to the snippets here it's actually a little bit different than the pre request script if you go to pre request script we can see there's only a few here but if you go to tests then there's a bunch there's a bunch of different ones ok so let's just go through some of them and I explained the most common ones and some useful ones obviously we can get environment variables and global variables just like we did before environment variable like we're currently in the Amazon environment so if we looked up if we looked up like the shopping website or something like that let's take a look if we looked here if we type in any one of these we get the value out okay same thing we can actually set those from here if we wanted to after the tests came back so maybe like if the response came back and then we did find something we did find a term or whatever above what like we found what we're looking for then we could like change them with the variables and run another request and like chain them together like that but that's not what we're doing right now um you can again it send a request but here's one that is immediately catching my attention that's pretty simple and easy to understand status code code is 200 so if I click this ok this pops up it says postman dot test status goes 200 and then I just make sure that the status is 200 so when we ran this we got a 200 ok so let's just try to send this again and see what happens ok if we go to test results it says there was no test for this request but now if we go run this again ok with this test in place as you can see test results now has 1 out of 1 so let's go to test results 1 and then as you can see it's as it passed because status code is 200 because status code was 200 ok but let's say we were checking for let's say we type in a bogus URL okay so like I'll just type in a bunch of F's here this URL I don't think exists when I run this then maybe it does exist or something hmm I'm trying to get it to fail here we go send API slash users slash ten or something come on just give me a just give me a four for when I need the four or four area um air it doesn't pop up oh my goodness alright well the point is if I was getting a 404 error then this would feel actually let's go like this okay did this will demonstrate what I'm trying to demonstrate let's just go to there we go test result failed so the check we're making was we wanted the status code to actually be 404 we're trying to make sure that it is 404 and that's when it is considered passed so since we got a 200 this is actually considered to fail so it says fail status code is 404 the expected the status code 404 but got 200 which is kind of a funny thing to check for but that's just demonstrating the idea okay so that's testing results pass and fail and also when we run collections like these test results come in handy because when you run the whole collection then all the tests will to come back together which is nice okay but let's change this back to 200 okay because that's the proper functionality and let's just keep going down a few more so we can check for code is 200 what else responsive body contains string so let's let's do that okay so contain string let's just click on this and then we're just making sure that there's something in here is um is there so let's just grab Janet okay and then just like pop this in here like that hit send again and as you can see boom now we have test results two out of two and it says body matches string okay which is because Janet here is there however though if we put um Janet with a double tee then or I don't know let's put like Jackson instead we're looking for Jackson inside here which is not there and we hit Send then we fill obviously okay so as his body matches string I'm expected to see Jackson but it didn't see jacks it's pretty much what it's saying alright but of course we can put that we can put Weaver this should pass again because was Weaver right there that'll pass yep and that kind of explains that one okay but now we are starting to get some more interesting things so um the others also on here response time is less than 200 milliseconds this would be useful if like we wanted to make sure that our website is really fast or something like make sure it responds quick enough you know amaz almost taking kind of a long time okay like we could run like some tests in here and be like oh if response time is more than 200 then something's wrong blah blah blah display something pretty much anything we can just like test for the amount of time but I mean this is 200 but we can send it to a thousand if you wanted to we can put it to anything we want all right but let's just put 200 and run this as well we should have three passes cool and um now let's uh instead of just looking at just one and see what all the users we get the whole thing and again we have all the passes because of course that Janet data was inside the entire thing so it still passes but now now let's say where it gets interesting is or another one is you can like check the content-type header so like okay make sure we're getting JSON back our mate make sure we're getting HTML back or make sure we're getting an image back or something you can kind of like specify the content time but you're getting just like enforce that you can check that out if you want but we're just gonna check this last one here it's called JSON value check okay so this one is cool because oops because it allows us to really dig into the JSON data and then we can really check things in like and make sure that things were correct like if we posted something to an API and we created it and then we went to I share it posted correctly when we get the response back we can like dig into the JSON response and whenever it makes sure like it was right and this in that like oh I'll make sure the post request was successful like actually here there's another status code request to make sure that the that the on post request was successful because 200 is for get requests right mainly forget requests it's like okay - um status code 200 I found the web page here it is but - um anything 200 is good but 201 and 202 I believe is if you post something it's like oh yeah we posted it it's good here's a response blah blah so I mean you can do that there's a bunch you can check them all out if you want but this Dom we're just gonna continue don't want this one so sorry so here um what's going on here is we are getting the json data back in the response so the postman response object we are converting it to a json file or json object with the json and then we just get json data here saved in a variable okay and now that we have json data we're able to just use dot notation to dig into any of this json that we want pretty much okay and then we could just say oh whatever data is in the json it needs to equal something and then we can use that as tests in assertions okay so let's just try this so json data so the first thing we have is page let's try page so because jace we have json data which is this here this bracket here then the very first thing is page the very very first level um this page so we can actually do this and this should should equal one so when i hit send there should be a fourth test and it should be passing oops oops i don't know what the issue is oh there we go I think that was the issue all right there we go I had a typo there so test results um the the page does equal 1 but like if we put maybe 2 here which is not equal then they should actually fail and as you can see yes it does fail because page the page thing here in this JSON is supposed to be 1 not equal to 2 but let's say we wanted to dig down like really deep like arbitrarily deep let's dig back down to jannat again okay ID 2 and just let's just make sure that her um her last name actually is Weaver or something like that okay make sure her last name is Weaver so how will we do that is okay we have our JSON data here you guys probably already figured this out if you know how to code but just I'm just gonna follow I'm just gonna follow through for a completeness sake but we're not gonna go to page we're gonna have to go to data which is also the first level so we can go directly to it but then once we're in here then we have a list all right so we have a list of JSON objects in here itself so we want to find Janet so this is a 0th one this is the first one so it would have to be indexed at zero data now we're in here okay and now we just keep using dot notation and we want last name right so now we just type dot last name our last name and now this should equal Weaver okay so I'm just gonna copy this and I'm going to pop this in here just like that but make sure it's a string okay because it's a string type and hit Send and this test result should come back is pass and apparently not let's see what the issue is oh because the okay this one let's say 500 less than 500 now we should all have a pass make it a little bit easier on us okay so actually this previous test field that wasn't the one that we just did so pretty much this is working as intended we're saying okay if the JSON data they'll be digging down below blah blah of this key if the value is equal to this then we consider pass if not like um if we put like huazi cool I don't know what that is but if we use that then it would fail okay you would say that the certian air Weaver but was expecting huazi all right so that is how you run test scripts in postman for your response objects um or from your HTTP responses or whatever you want to call it you can also run these at the collection level just like you could with the pre request scripts as well okay so when you run the entire collection then all these tests will be run after it and again you can you can make variables in here as you can see JSON data right here and you have full control over everything in the code with within your request any responses to really test anything you could imagine pretty much okay but I gave you all the basics that you guys need now it's your job to go out and actually apply these things to figuring out how to use postman to solve whatever problem with the API as you're trying to solve okay but that's pretty much it for scripting pre request scripts and tests and I'll see you guys in a few seconds to go over on the next thing alright you guys so now we're gonna go over pretty much the last thing in this postman crash course and that is setting up mock servers all right so I mentioned this a lot at the beginning of this crash course we kept saying old mock server this mock server that that's because up to this point we've been doing a lot of client stuff so we might have been working on or creating like dummy client arm requests so we can like create basically any client request we want and then we can send it to any existing API that or you exists and then get something back ok so we had flexibility around shaping what the client was happening with the client but the API is had to already be there in place now mock servers will allow us to do the flip flip option of that let's say the API doesn't exist okay maybe we're developing a client and a server for a client or something and both things need to be developed but the server doesn't exist but we need to build the client like one of them needs to exist to be able to test it so we are able to UM work on the server and then send mock requests to the server using postman which is what we've been doing up to this point we can just create whatever quests we want and paying the server but let's see we're all working on the client-side and we need to send requests somewhere and get a response back but the server doesn't exist yet okay if the server doesn't the API doesn't exist then we need still need somewhere to test it so that's where mock servers come in we can create mock servers which basically says oh if there's a request to this URL - yeah - this specific URL on the server then reply with this we're basically gonna be hard coding in responses to specific requests so like if it's if if like oh this specific request ins with these specific headers and this specific URL and all this yada yada comes in send back this specific response be it JSON or HTML or whatever kind of data were sending back the entire response object with its own headers and everything so it's kind of an overview of what we're gonna be doing now we're actually going to postman and go through actually doing an example with this you can see see how it's done and maybe understand it a little bit better so let's first start with creating a new collection okay so you need a box server I mean we need a collection to create a mock server because every mock server has a collection associated with remember a collection is just a group of requests and that kind of makes sense because we need a mock server up and running and then we're gonna have a bunch of requests that can be sent to that mock server and it's just nice to have all of those requests together in a collection okay so I'm gonna call this mock server requests name of this collection because this is gonna be when she requests going to the mock server and let's hit create so that's done but there's zero requests in here so let's just add one request really quick and we're just gonna call it request one alright so this is gonna be request one and um we just need a after we're done creating this request basically we're gonna have to have on the mock server know what to reply when this requests one specifically this request one comes in so let's just create request one there nice so we have a collection we have the request that we're gonna send to the mock server and now we actually need to setup the actual mock server within um that's associated with this collection with this collection so we hit this little button here and if you go over to the right here on this tab it says mocks and it says this collection is not being mocked okay a mock lets you simulate endpoints and their corresponding responses and collection without actually spinning up a back-end so that means yeah if the back end doesn't exist then we can simulate endpoints and points are just URLs pretty much like the path like oh if you reach this certain URL path then um then do something respond with something so let's just create um click create mock uh create a mock server and now we're just going to create a mock server so we're just gonna call it mock server all right very straight for I'm create a version tag this a little bit Vance we don't need this right now she's saying if this server is going to correspond with a specific API version maybe we're actually working on a new version of an API instead of like creating some from scratch and then we have to have a version yadda yadda but those are details that only matter when you're actually doing them and then also you can have environments um I'm just gonna click no environment but you can choose to import all the environments for this mock server so that all the variables that you have in that environment are already existing but we don't need that now either and they make this mock super private we could if you want but then you'd need a API that occation key and all that stuff and we're not gonna set that up right now so we're just gonna keep it public so let's create and create the mock server and that was pretty easy right it says mocks ever created we are done and I'm all you have to do is to call them mock server is just go to this URL alright this URL right here in orange and pretty much what this is saying is ok this is your mock server so when you go to this URL anything that comes after this like treating this as a domain and it comes after this can be um created as a mock server API so like ok if you like ok slash users or something um this slash users then you were gonna have to need to send something back basically this is just standing in for the domain maybe if we had an API in the future like this would act like if we were actually working on a project that needed a server using PHP or whatever server code you want to use or Django or flask or whatever then it would be like okay WWE my server calm slash API or something instead of this here but this is just a standard alright so on that little URL is right here it pops in as you can see now when we go to mocks then the mock server is here and there's a URL associated with it which is pretty cool so we're basically saying when you reach this URL then we are now integrating acting with our mock server so now we can start creating hard-coded responses to specific requests so if you click this button it's gonna copy the mock URL all right and now we're gonna go to the request ok let's close on with these tabs we don't need these anymore all right so now we have the request open and let's just pop in the mock server base URL okay the very base one the domain and nothing else let's hit Send and see what happens and as you can see this thing pops up okay this is the response we got so if we're writing if we run a get command just to the base mock server URL that we have then we get an error back and it says mock request not found error as in whatever's associated with this there was no response associated that we didn't find and the message says this collection does not have any examples um an example of something we're about to create it's a thing in postman right up here on this top right we're just about to talk about it but it says this collection does not have any examples please examples to the requests in this collection to enable mocking okay so all an example is is just the response we're gonna send back for a specific requests so so we're basically gonna say um well let's just go here up the examples okay it says no examples added save responses and associated request examples so we're just gonna click add example okay we get this new tab as you can see over here if this says get this is a request and then if we go here this is an example it actually says ie um eg dot which is a Latin abbreviation for example for example I think it's like or go something but it doesn't matter but so this is an example tab and now we can see that this example is actually set up so if when we were when we sent our question we got this response and the cool thing is that this response is exactly the same as what this response down here is okay that's because we're saying oh when we hit when we're in this example we're saying well we hit this and we hit this URL with these parameters and these headers and this body in other words anything the example requests up here anything in this white box whatever um this is specified exactly whenever that exact thing comes in to our mocks server then give this exact response okay so this is the base mock server and if we send that with note with no path coming after it with nothing after it at all and nothing else in it at all send back this JSON data with a 404 not found status okay and then have all the headers and stuff - okay this is JSON and this is clearly JSON so let me go back to the request and we send this again that explains why we're getting this okay sent that's what we're getting this like everything this is actually an error that was Auto created by postman now let's say we actually typed in something crazy like like whatever a bunch of stuff and then we hit Send um then we get the same issue um I think postman is just like autocomplete into whenever there's something doesn't exist then this pops up which is very handy but what we want to actually do is create a new example or did I save it what we actually want to do is create a example for um maybe another endpoint another URL so we can actually see how that would go now okay so let's go let's just duplicate this to make it clear so duplicate this and we are going to rename this to request to okay and copy that in there and then we're just gonna say users okay and then here this example well actually we can just go back up here and just create another example and then we're going to call this response - all right so we request one response one which was just a base and we're getting back this error and then now we're doing a request to in response to so now I actually want to add in something different so if we actually reach this um URL endpoint the mock server or base domain + users then I want to reply with something different okay so here we have it filled out on parameters I'm just gonna keep it light it makes sense it should be pretty straightforward that you can put in whatever you want here okay but I'm just gonna keep it empty because that's unneeded so we're just saying when we hit this URL end point then send a 200 okay response and then let's send um you could just send raw text so it could be like okay hi whatever but let's just send back JSON data so let's check JSON data as you can see you can send back XML or HTML or anything but let's just send back JSON data and it says slash users so let's um let's just make some dummy JSON data okay so this is gonna be the hard-coded response that we're gonna have to this very specific request and then let's just say um users like that and then we just say like name is Erin and ID is one cool and then let's just do the same thing um there we go but let's change this to name is cause II and ID is - okay very straightforward so I just create some dummy JSON here as a response so now we're saying on this mock server whenever somebody goes to this mock server um slash users then reply with this JSON data okay this JSON data with the 200 okay response okay and I think we need to actually say some of the headers too so let's just go into here other one and um maybe just copy all these or let's just run it and see what happens okay so let's run this alright guys so yeah I don't know why I wasn't getting the correct one maybe I didn't save it or something but now it's working so I created this this hard-coded respond to this JSON down here like we just did a few seconds ago and now um I go into this slash users in point URL and now when I go to request um to and I go to that same exact URL at the same endpoint slash users and I hit Send then it works as expected I didn't change anything okay um I don't know what it was I think it was yeah I just don't think I saved but if we view this as JSON then you can see that the response we get is exactly what we said the example should return we said example should return this stuff if we go here and when we actually go there on a request that's what we get back very very straightforward okay um originally I thought it was because all the headers weren't there but we don't need all them but I mean we can fill it out if you wanted to all these headers here the easiest way to just be like I actually duplicate this other one that has all of them in there um here and then all the headers already there and then just copy and paste all of this code this was JSON response instead and to here like this okay paste that in and then let's just actually call this response 2.5 and um say slash users I guess we're doing this really quick and save that ok should be saved users yep um and let's just put Aaron 2 in Kazi 2 just so we're aware that it's the right one a little difference in the response so that's saved let's just let's just delete this one I guess response to it delete and there we go so that doesn't exist anymore now this example should be associated with this endpoint so now we go to this endpoint again and we hit Send then as you can see Aaron - and Kazi to pop up which is the change we made and all the headers are there okay which is that once we copy it over so as you can see it autocompletes to json before remember it was just like Oh autocomplete comm HTML and it was looking kind of ugly that's because we didn't have the content type set to JSON and stuff because there is no headers and some of these headers are are mandatory by good practice pretty much but that really simplifies things if we just copy over all of the headers from the original example okay over here and that's pretty much it you guys for mock servers so you're able to create a collection with a bunch of requests in it and then you have a mock server base domain associated with that collection and then all the requests you send to that domain can be given hard coded responses by creating examples okay and that's pretty much the overarching logic of it very simple just remember that and you guys can pretty much set up any mock server you want so any request that comes in you can specify exactly what you want to get sent back so it makes it very easy for developing client-side servers or client-side API s and whatnot so that should be it for the post in crash course pretty much thanks you guys for watching hope you guys learn a bunch and I hope you guys have fun playing around with the API is whether it be your own or ones you find on the Internet yourself there's a lot of cool ones out there but yep that pretty much wraps it up you guys good bye hey what's up you guys so if you'd like that video if you have an epic three-part free master class that teaches you how to go from complete zero to becoming a six-figure freelance developer with Python if you want to check it out they click click the link below in the description there should be a place where you can put in your email and your phone number and your name and you can sign up and you can get direct access about it there's a lot of free value there just go check it out I think you'll really likehey what's up you guys so welcome to the postman crash course what post been super useful it's one of the greatest tools you can use if you're working with api's at all and if you want to be serious in the software industry you need to know what api's are and how to use them so this tool will save you so much time all right we're gonna go over all the basics of postman we're gonna be going over how to use it all the functionality the whole UI like what its uses are and do a few examples and go through pretty much everything is it's pretty exhaustive but not everything but I mean it'll it'll be more than enough to get you started so we're gonna be going over how to create mock servers how to use variables and how to send requests all different kind of HTTP requests to any any of server or web server you can think of any website getting all your responses back all the analytics of it all of the data and all the statistics that you get from it this is a bunch of stuff it might seem kind of wordy now but when we get into it you'll see and it'll be pretty great so let's get started hey guys so welcome to the video before we get started though Before we jump into it I want to tell you that we have an epic free three-part master class it teaches you how to go from being a complete beginner and programming not knowing anything if you've never written a single line of code and the steps you can take to become a six-figure freelancer or a software developer so if you want to learn how to go from there to there click the link in the description down below it should be down there just gonna pop in your email address in your name and we'll send you an email to the login page for that and you can access it completely for free and it ends with a an exclusive webinar if you want to check that out too after the three parts so if I guess it's kind of like a four part masterclass but I definitely check it out alright it'll it's just a lot of free value and just we want to offer that to you so check it out all right you guys so let's start it with be posting a crash course alright so just a few prerequisites before you get started to understand how to use post pin and everything I'm gonna go over in this crash course you're going to need to know about what api's are about what rest api's are what web frameworks web servers and web clients are and stuff like that a lot of like online coding things and what hTML is and JSON and XML and I'll be familiar with all these terms in order to be able to follow along because you need to understand all this stuff to even use postman to begin with so if you don't know that then go back and learn how to do that first and then come back to this I will be explaining a little bit as we go just to like jog your memory so if you kind of know what those are and I mentioned things and you will be ok and things will come back to memory but if you have no idea what those things are then this crash course is not for you you should probably close out and go learn those things first start with a start with HTML and some other simple web stuff and go up the frameworks and and all that stuff and then you'll be ready for actually testing API stuff Oh an HTTP request and stuff as well that's very important to know that's what API is are based on but besides all those prerequisite stuff let's just get started okay so postman so postman in a sentence postman is a tool that you can use to work with api's all right so it basically allows you to test api's build api's and like create mock api's like servers like mock servers or mock clients and whatever so you can test them so while you're developing let's say you're developing a server or something then you can test it with this tool to make sure everything's working properly and vice versa so if you have a client then you could create a mock server or I mean if you're creating if you're trying to program a server then you can use postman as a mock client by sending requests to it like HTTP requests to it and whatnot but that's just a little overview of what it is let's just get started now so we're gonna want to download it first um you can either use the native app or the Chrome extension but I realized that the Chrome extension is deprecated as a saying right here but yeah let's just go to the web like here we go so this is postman it's just a plication we can use and we're gonna get into it very soon all right use cookies got it and pretty much what you need to do is just download it first okay so click download the app and yep just download it for whatever operating system using I use it for I'm using it from Mac right now and I already downloaded it but yeah so after you download it and you create an account and all that then we can get started with postman okay so go do that first I'm gonna continue on because I already have it downloaded and I'm gonna open up the postman app right now all right so I have a postman over here open it up and get this started loading awesome so it's loaded up perfect let's get this on a separate desktop cool so now I can go between my browser here my chrome and my postman so when you open it up you should probably see something like this or something similar you can just close out of this we're just gonna go straight to the UI I want to show you all the basics first now that we have it downloaded so I just want to go over all the UI and what all the buttons do when everything means and kind of just give you a tour of postman before we get into anything advanced all right so this is kinda like the basics like the basics crash course portion of the entire crash course all right so this is postman we are in postman and like I said it's just a tool that allows us to work with api's we can send requests we can crate mock servers and yada yada here we have all of the different requests we can do so we can basically send any HTTP request I'm here get and post are the two most common ones but of course you can use put and delete and all these other ones that we use occasionally but mainly just get in post alright and then when you are wanting to test an API then you can just use things here so let's just give a simple example all right so let's just say we want to test a this so we just want to get Emma's on comm you hit send then it will it there we go it grabs the the code the HTML code back from when we type in Amazon a common tool browser we get all the HTML code back and we can actually hit preview here and you can actually see that actual web site so my postman is is just a way a tool that gives you a lot of like leverage in different ways to change parameters and whatnot to work with api's and web servers and all this stuff okay we're not gonna be using Amazon the con when you season this because everybody's familiar with the webpage and then they understand how this is working so if we use a get request on the website then boom we get it right back alright but we're not gonna be using this anymore that was just for demonstration purposes so now let's actually use an example and I'll explain what everything is as we go okay so let's just do a get request first okay so let's um I have this cool JSON place all the website right here which allows us to it's a free open API where you can go into it and you get JSON back it's just that's why it's called JSON placeholder but we're gonna be using that right now at home for these basics let's just start that so yeah you can you can choose your type of request here we're just gonna do a get request and then when you hit Send it'll actually send it and get it back just like we did with Amazon so let's do that first and we'll hit send and as you can see we get our JSON back okay so if I actually pop this into chrome as well we would get the same exact thing just like we didn't post me and we just get some JSON back alright so JSON file if you don't know that is then this will make sense but this is JSON data and we're getting all this back alright just like we are in postman but here we have all the different options here to view it so we have pretty which is cool because you can actually collapse the JSON data or if it's XML data or whatnot well you could you can view the raw data which is just a raw string with formatting the preview which is what it would look like in your browser that's why when we went to amazon.com we actually saw the actual thing is they just HTML code because this is what it looked like in your browser and chrome it's auto formatted though but I mean that's just like extra fancy thing that chrome does and most browsers do but it's supposed to look like just like this just a raw string okay and visualize beta this I don't know what that is it's new I haven't checked it out too much but so if we are getting JSON data back then this will automatically go to JSON but of course whenever we are using a get request then we can have all different kinds of data coming back so whether it's XML or HTML just like we did when requesting up a webpage or text in general or whatever also when we are sending a get request then you can actually set your query parameters here so this is your query string like if you want to say like okay parameters like something like user ID oops user ID equals six like if you're gonna have that in the URL when you're calling an API then you can actually see that it auto cottle fills it out first here but likewise we can also do something like this right like hello this is a tight tool okay and it'll auto fill it all out for us and makes it very easy to construct these things so you have to type it from scratch so let's just get rid of that but yeah basically you can write our key value pairs here for any query string parameters and you can also set your headers and your body here okay so body is more important when you're actually doing post requests right but if you want to set your headers like content type or whatnot then you can actually you can actually specify these here okay or anything any other headers that aren't done by default then you can add them in here and it should actually autocomplete I think yup so like if you have like content type or like content length or something or whatever then you can just pop that in and then yeah that won't be auto generate for you you can also toggle these on or off so if it's on then it'll be it'll it'll be used but if it's ticked off then it's as if it wasn't even there to begin with but it's just nice to have it there because this is a tool so you want to make it easy to test api's and all that so let's go back Oh another thing I want to point out is you can actually um save so like I have this get request here right and I have like a bunch of different query parameters and different headers and bodies and everything like set up in a certain way and perhaps I want to keep testing it over and over again and I want to save it then you can actually save it here by using this button okay you can save this request but another thing is that there's a history of everything you actually sent so we sent to get requests already you can see the amazon com1 and then the one that I just sent so these will always be here and you can click on them and it'll actually take you like oh it'll open up another tab for you another tab for you and allow you to look at the requests that you sent okay so that's nice if you want to go back in your history like keeps everything there of course you can clear it all but yeah let's continue Oh another thing I'd mention whenever you are doing a when you send our HTTP requests then it'll get you the status code back here it also tell you how much time it took to do the request with all the stats there you can see the DNS lookup and all that stuff you know what if you actually know what all that means and also the size of the returning file the response file okay and then you can also save responses here but yeah I think you can also when you send you can actually send in downloads instead of just sending the request whenever you get the response you can actually download this entire file separately okay but that's only if one if you only want to download it but I think that is pretty much most of it for the get I think did I go over this headers oh this is the headers that we get back in the response so we'll have the date that the response was sent down the content type of course its application slash JSON and the reason UTF um utf-8 the char set blah blah blah and like all this other stuff I don't know what all of this means but I mean these are all the headers that we got from our JSON data which is very clearly JSON data okay and yeah I think that's pretty much it forget let's for get requests let's now try post requests so I believe in this open API what we can do here is they actually have an open API where you can put posts so now we can test post requests and we can send those out to this to this URL here and actually test post requests now so let's just turn on post request they're real as you can see the other get requests popped up here when I when I call it again but now let's do post okay so if we go into posts of course we have our query parameters and whatnot so let's just try this sending a post out as you can see here they are expecting a user ID or that isn't allowed key key and one of the key value pairs in on this API so let's just pop that into one of the query parameters okay let's just say user ID equals I don't know six or something or let's just put two whatever it doesn't really matter I don't know why I'm deciding changing it but we can put that and you whenever we send a post request then what we get back is actually the ID of the post entry that was just created okay so when we hit sent we're actually going to see that the ID comes back of 101 and you can see the post request pops up here but let's go back here let's go over some of the headers again you can set your headers of what kind of content you want to be putting there or ascending through and any other header few fields that you want and of course when we're doing a post request you actually need to specify what's in the body that's the most important part okay so within the body we can actually send nothing which would I guess do nothing it's just kind of useless maybe useful in some cases but form data of course is what we can do if you just want to send like JSON data up-and-down which is kind of what we're doing here by sending user ideas um user IDs and whatever titles or whatever it has I forget what was there me let me see V add our user IDs or regular IDs or title or body and all this stuff but when we're doing post of course we can send form data we can send form URL encoded data or raw data just straight string just straight string data or even binary data okay so if we wouldn't actually upload images then we could very easily just select an image to post to this here okay if our API allows it if whatever web server we are coding up or using or accessing if we're maybe using yeah yeah if we're coding our own web server and if it allows it that we can send it okay yeah I mean if we were sending a JPEG or something or something like that if we're sending a binary JPEG please like to the JPEG image here or PNG something then we could actually go here and change this it could be like image slash JPEG or whatnot and then that's how we could send a post across with an image and then of course we would have to select the image file here so you could just pick a image from your computer um but yeah all right well I think that pretty much sums up most of the basics here I think I went over pretty much all of the buttons of course he can get the headers again from your post response and test results we'll go over that later maybe and what else did happen I seen collections collections are just collections of different requests pretty much that you can put together you can like create them and just kind of keep them organized if you want or you can just like do test one by one like we were here um this gets a little bit more advanced maybe we'll do that later but I think I've gone over most of the basics here so you guys shouldn't know how to send getting post requests and how to set all of your different parameters and whatnot whether it be quarry string parameters or headers or your body and your body types and all these different things and you should be able to see how like how to see what's coming back and whatnot and it's just very useful if you are working with api's and you're trying to like test if you're like coding up a client's side thing and you want to have a mock server or to like compare if things are working correctly then you can use postman to like create create dummy requests or like mimic some of the requests and see if what's getting coming back is what you're expecting to come back and so forth basically it just allows you to fake servers and fake clients and to make sure it's working correctly just so you can test your API so whether you're building it or testing it or or just using an API but yeah that covers all the basics and I will see you in a few seconds going over whatever we go over next all right you guys should be a few seconds later for you but now I just want to go over really quick about bulk editing query search query string parameters and creating new requests and collections credit collections and saving requests to collections well it's still pretty basic but I just need to go over it a little bit more involved but that's I'm going over it now so let's say let's create or let's change it first let's let's just query amazon.com again I actually I'm gonna use this again amazon.com all right so we can preview it we can see that we have the webpage here and have the HTML code here but let's say we wanted to actually search something on Amazon okay so let's I believe on Amazon if you just put s that's the search URL so now it's getting ready for a search and then we just have to add into the query string parameter here um I believe it's K I don't know why it's called K but we can put anything we want in the value so if as you can see when we're typing it down here it's Auto completing the query string parameter so we're gonna say amazon.com search and the term search term we're gonna search for is iPhone so let's just hit Send and if we click on preview then you should actually see that iPhone was complete up on the arm in the search bar under all departments and I'll be can see a bunch of hyphens pop up there might be like another parameter here for departments like something might actually change what this is instead of like just all the parts you get to go to like technology or something I don't know I guess there's something something there that would make more sense for iPhone but yeah that's that and let's say we maybe have another one so maybe there actually is one I don't think this is actually true but like let's say if we had like Department we could be like all or something okay Department equals all and that could be like this now I want to show you bulk edit so if you go to bulk edit here on the right instead of having this nice interface using key value pairs you can actually click on bulk edit here and see everything you have as just a string and this is useful because you can just go in here and just copy and paste or just copy it and then you can actually go up here and click plus and you can actually type in amazon.com again oops comm / s and then down here go to bulk edit and then just paste this in here and go back and as you can see it's all auto completed so you can like copy request that way you can also just right click up here and duplicate the tabs but that's actually not a true copy sometimes like the names and stuff still get the names will always be the same or something like that so I don't like using that I always just create a on do one from scratch but let's just get rid of this one don't save it let's go back to this request that we had okay so search for iPhones let's turn off the bulk edit mode going back here so we have an iPhone search now let's talk about creating a collection and saving requests to collections all right so once we have a request here we have a get request on Amazon just searching for iPhones then we can click Save over here alright and it brings up this save request little window so in order to save your request you actually need to create a collection um it's kind of just like a folder for a bunch of requests I mentioned that a few minutes ago but let's just click create collections down here and let's just call it Amazon searches alright hit this little orange check sign and now it's selected if I click back on it you can see all your collections here and then this you can't save anymore but when I select Amazon searches I'm in here and now I'm able to save a time on services so the name of this request it's going to be Auto completed to whatever the URL is the query string but I actually just want to make it cleaner and say Amazon search and I'm just gonna say iPhone just like that okay you can put a description if you want but that's optional I just put hello sure why not and now we can just click save to Amazon searches all right so now we save this request you can see the name up here change to Amazon search iPhone and if I want to change the name then I can I find this little down arrow then you can see the description you can also edit the description down here you can even use markdown which is pretty cool save will collapse this back up so that's that and now now that we have our collection made if you I should click on collections over here on the on the left you can see that our Amazon surges collection was made and it says there's one request inside let's just click on it and as you can see there's Amazon search iPhone okay now let's just create a another one okay so let's actually use this well let's go to bulk edit and just copy all this oh not that much I mean you could actually just like type it in yourself but I got a bunch of these different parameters if you wanna copy over it's actually useful turn this off go to this plus sign create another one I'll let's just say it's Amazon calm slash s again go to the bulk edit paste it in go back cool and now I don't I don't want to search for iPhones anymore maybe I want to search for MacBook okay or just MacBook and now let's pop send sending the request waiting for the response down here go down to preview and as you can see now we have our search results for a MacBook and if we scroll down then there's a bunch of mac books available okay cool so now I'm gonna save this to alright and I'm just gonna go Amazon search and it's gonna be MacBook okay and no description this time okay and then we have it selected you can already see our our previous one iPhone was created down here you can see it faded out and we'll just hit save and boom there we go so that's how you save your searches okay so that way you have to keep typing from scratch every time you can close out of both of these so when you open up launchpad I mean on postman and this is oh yeah this is launch pad too you can go here and there's a bunch of other UI stuff but later later now we have our collections here so we have our history of course we can go through um you can delete all this stuff let's just delete these why not delete okay so they're gone forever but if you go to collections then they're still here I mean you can delete these two by hitting these buttons but now we have the ability to see these again so when you click on it they pop up see its italicized though so if I go to other one then they don't stay open but if I want to keep it open and then you just can hit Send and then see it'll it'll on italicize right now after I send it and then now when I select macbook then it just opens opens it up in another tab there we go so we have iPhone and MacBook and you guys get the idea okay well that wraps up creating collections and saving requests and using the bulk edit mode and I will see you guys in a few seconds again to go over whatever we go over next alright you guys so now we're gonna go over variables in postman so variables are exactly what they sound like they allow us to set variables and have those things change wherever those variables are so if you have some variables in this URL here like if you had something like a variable here or whatever slash variable one or something that we could actually set this variable somewhere else and then have it this be filled in with whatever the value of variable one is so there's actually two different ways we can do variables um there are path variables and then traditional we're not traditional path variables and then like real like global variables I'll go over to path variables first cuz it's very simple in straight-4 it's like a mini variable pretty much only for paths in the URL and then real variables are like variables that are like within postman that you can set variables like within the entire app so that whenever you change one of the variables then in every single request everywhere then that variable is change or something like that like they're very very powerful but let's go over the path of riyals first which is very simple this will make more sense as we get into it okay so we were using this nice API here let's just click this again send a get request to see what comes back and we get a bunch of stuff it's been a couple days from me so I might already gone over this I'm just kind of half refreshing myself and half reminding you if you're coming back or something but all right so we have this thing we have a bunch of posts here all right and if we could filter by perhaps if we use ID then we could like oops then we could filter it like that and it's send and then just get the one with all the user ID of one or the mean the ID of one and also if we did users then we also get a bunch of stuff here and we can again filter by the ID of one okay send that and boom we have just this one instead of all of them so now I want to point out that we are able to change the path here so users here we can actually change users to posts like we did before and if we hit send again and get the response back then we have a different post here so perhaps we wanted to go through all the posts and users that have this same ID doesn't really make sense logically but I mean this is just for demonstration purposes so as you can see this is the portion that's changing so if we wanted to create a path variable there's a little secret trick here it's kind of hidden and what you actually have to do is um get to the portion where you want to have as a path variable and delete it and then just put a coolant okay and then I'm gonna put path and as you can see if you look right down here like look great in this area when I type when I start typing this thing called path variables magically pops up okay Matt just magically pops up there and that's because we're able to set path variables okay so I'm just going to call this path 1 or path of r1 or whatever cool and down here is where I'm able to actually set users or posts or the value of the path variable so the way this is working is because this is preceded by a colon this is considered a path variable and path 401 so whatever this is is going to be filled in with whatever we type in here so user um this is going to be the same as what we just had oops users sorry there we go so we have a user with the ID of 1 and then same with posts send and it works as expected okay so this might seem a little bit clunky it kind of is I mean right now for this example like you wouldn't need to use it for this one but it's very useful if perhaps you have an API where you're working with you're accessing something like maybe you're accessing YouTube right you're accessing YouTube and you have like you want access like different comments on a video and every comment has an ID okay but you want to iterate through all of them or something like that then you could it could be very simple like um it might be like youtube.com or whatever yeah just pretend this is youtube.com and then you could have like or slash video 1 whatever it is slash um comment comments slash and then you could have like that I like the comment ID or something like that ok and then you would put in like ok comment ID and then from there then you could actually like put in the different numbers and send it and then change it and keep iterating and just keep going up and up and up or whatever you wanted to do like it's very useful for that and then of course you can have multiple ones so comment ID and then you could have like whatever else after that like comment ID - etc like you guys get the idea but let's go back to what we had before yeah we don't need this oh and the last thing I want to mention about these is in order for this to work this has to be part of the path path variable okay and you see part in the path up here in front after the domain with all the slashes and stuff it can't be part of the parameters okay so no you cannot if you wanted to go like okay path and then ID if you wanted to go ID here then as you can see it's getting changed here it's not actually popping up as another thing here so remember when I typed in path then imagine we popped up here right if I type another slash and then I typed in here and I typed an ID see how it pops up down here but if I type it in over here outside of the path and after the variables the query string parameters I mean the app yeah the the parameters after the question mark then it won't work okay it won't so we can't do it that way that's the whole point of these down here okay because you already have the parameters pretty much so this is actually two parts of it it's just as part is hidden this is how you change you can use um put variables in this URL on the left side of the question mark and this stuff up here the query parameter is how you use variables on the right side of the question mark okay and that is pretty much um path variables so let's get into variables next alright so now we're getting into true variables like real traditional variables home I recorded this whole segment then I got deleted which is kind of annoying so I'm starting over on that's why this looks as different all of a sudden but pretty much variables true variables allow us to pretty much put anything we want in here anywhere at all and to specify what the variable is so pretty much it is what it sounds like unlike path labels we're limited to only changing the path over here like per per parts of the path or query string parameters we're only able to change like parameters over here variables we can change anything we want and we can basically be a full freedom with it you can create variables at many different levels and postman so like one level is collections so if you myrrh we created this Amazon searches collection then we can actually set variables at that level that's what I'm gonna demonstrate first but you can also create it at the environment level or the global level and just explain what of environment is really quick we're actually will do that later let's just actually this videos can be better because I'm gonna go in a better order but so let's just create one at the collection level first alright so remember we had this collection that had two requests were searching for iPhones let's send that in and you can see the responses already there but we'll just send it again if it will hurry up bear with me guys there we go so iPhones and then also Mac books right I'm not gonna demonstrate this because it's already there it's exactly the same but let's say that in the collection we wanted to set a variable to find some similarity between these two so within these two requests we can tell that this part here amazon.com /s s is a short for search is the same in both so why don't we set that as a variable okay so let's just copy that and hit copy and then go over here to collections hit on this triple dot thing go down to edit and all now that we're in here in this collection there's like a little tab here called variables we go there and now we can specify a variable okay so let's just specify a variable called Amazon all right Amazon and then the value we're gonna give it is amazon.com slash s okay and it tells you the current value as well if it's changing over time but let's just hit update alright and now we can see if we go back here we go back to edit then the variables it should be there this little green dot telling us that there's stuff in there and we have Amazon so now that we have that the way we access a variable in postman is to use double curly braces just like that okay and as you can see it turned red to specify that to show that we're using a variable now and now we can I'll pop in the name of the variable which was just Amazon and this will actually autocomplete to amazon.com slash s as you can see if we hover over it that little um it actually tells you what the via the initial value of the variable was and then what the current one is and then also the scope so these variables only apply to this collection so if you use Amazon and anything within this collection then it'll autocomplete to that but any other collection or outside of it it will not okay so that's that let's hit send to just prove that it's still working I mean you guys can probably take my word for it you can test it yourself but I'm just showing proof reasons there you go that works and then again let's do the same thing but let's just copy and paste it should copy and paste the reason I mean you could you could argue that it this is also the same to the question mark and the K equals the search term in both which is true but I mean I don't think it's very it's not very good practice to just like do that because you don't want to like bridge the gap with the parameter question mark splitter thing here where the parameters start it just doesn't make very much sense like you have like maybe like a separate variable to keep the question mark there and then have like oh like a search term or something okay but let's just test to make sure this works as well get the get request for this one the Mac Book Search and as you can see it works as expected as well okay so this is pretty cool I mean you can have multiple variables of course in the collection and and whatnot but also there's a way you can slit global variables environment variables let's get into that now I'll show you global variables wifey let me explain environments first so we're actually gonna get into environments next right after this um in depth and how to create them and stuff but I'm just gonna explain what they are really quick so if we go up here this kind of like where your environments are this little rectangle here it says you can cite your environment there's no farm mines created we're gonna create one later but if you click on this little eye thing and then it says environment here and Global's okay so these are two other levels where you can create variables so we just created at the collection level which is like the lowest level or one of the lower levels and then now we're environment so an environment is just a set of variables that allow you to switch the context of your requests so that's pretty cool because we can set a bunch of variables with an environment and then whenever we were in that environment automatically everything um has those variables applied which is very cool so and then if variables of course just applies to all environments okay so this is like overarching no matter what and then environment so but we can switch our environment and pick one - how like a set of variables set so this is pretty cool like one example I just thought of is let's say you know how we're doing Amazon searches here maybe we have a we also want to search a bay or something okay and there have like two different collections or I mean yeah we're what two different sets of does happy clash there's two different sets of requests we have to do environments maybe we wanted to have like one Amazon search so or actually just like um I think I better explain it is if we wanted to have two environments like one Amazon and one eBay okay then we could have our request to be even simpler so instead of so this being amazon.com right we could just have it be like website okay or like shopping website or something like that okay and then have this as an environment variable and then whenever this changes I mean whatever we changed environments then like in the Amazon environment in the Amazon environment then the shopping website variable would be amazon.com and then the eBay environment this variable would actually change to something else so that these requests are like useful depending on are still useful depending on which environment we are so like let's say we want to also check a Bay for like Mac books and iPhones this is K for the search room for Amazon but it might be different for eBay but we're using variables you could just say okay search term you know something like that and but I mean this is always gonna be the same question mark and then equals always gonna be the same but this gives us a power here because now if we're in the Amazon environment we can just say shopping website is Amazon the comp search term is K I'll mean slash s2 right we need / s oops / s for Amazon but we could keep that we could include that in something or people like search whatever but the idea is that yeah you could you could use this same request for both Amazon and eBay to search for iPhones and Mac books just by hot swapping the environment if we had the environment set up correctly so that's pretty cool okay because yeah just if you guys still aren't we following then it might be like amazon.com / s and then search term equals iPhone but eBay might be like ebay.com / search term equals iPhone so the term here but it says K here and then um this will be / s and then it says s here but it says search here or something like that this isn't probably actually right but I mean that's just the idea of it okay so that is that let's put this back to Amazon alright because it's complaining that is an unresolved variable there we go and then make this okay and send it again last thing I want to talk about Oh Amazon typos bear see and that's actually a very good point um I was just about to explain that the issue with variables though is whenever you have a bunch of variables here suppose you have like five ten whatever variables in your query request string here then you can't actually see what's being sent okay because the variable is hiding what is here you don't have to keep opening like okay if you had like a collection variable and an environment variable and then a global variable or global variable is real quick I forgot to mention that let's go to global variables if you click on this little setting sign up here on the top right okay then you can go down here to Global's and you can actually set global variables so this is like things that make sense to be global so it could be like my name value is gonna be air in okay and then like there and you just hit save and then when you hit save it just automatically saves it blue global as you can see it's still there my name ahran and that pretty much just applies to everything every environment everything at all I can use this anywhere I want if I have if I type in my name it's just gonna autocomplete the arrant no matter what okay very simple and you can delete them by clicking on the X here that's global variables very straightforward but getting back to what I was saying but sometimes if you're trying to troubleshoot with variables and whatnot then it's very easy to make mistakes because you might have a bunch of variables and you can't actually see what's actually being sent I'm like me I just had a typo right but I might have not known that be like why is my request working what the heck oh this is so annoying I mean first all you can hover over it which is good because tell you it's an unresolved variable but also if you just want to see like the exact raw static request that you're getting on the response you're getting then you can use something called the postman console which is like a no-frills version of everything sending the requests and responses so we have our cool thing here with all the variables but if you go to the bottom left here the little thing a little icon when I hover it says postman console let's click on it and it'll open up a new window and pretty much what this does is it just shows us all of our quests so let's go back to postman and I'm using this variable here I'm searching for Mac books let's hit Send let's go back to this and as you can see now this little get request just popped up okay get amazon.com / s see how it auto fills out the variable for us and then it says search I mean then K equals Mac Book we can collapse it and then we can see the request headers everything in here absolutely everything the response headers and the whole response body but we can't see it because it needs to be larger anything larger than one megabyte can't be shown but that's okay because we can just go down here to raw or pretty and get the response string there if we want okay but that's just a nice little thing to allow us to troubleshoot if we're having issues with variables or using variables and we can't figure something out and you need to really like see at the low level exactly what's being sent and received um then we can go here to post on console okay if you don't this little icon down here on the left then you can go to view show postman console or use your little shortcut here um it might be different on Windows but yeah just looking like view or something or or or google it you can find the console Oh or whatever version of postmates using but that pretty much wraps up variables for you guys we're gonna get into environments next a little bit involved actually creating environments in blah blah blah and setting variables within dos all right you guys so now let's go over environment okay so I said earlier environment is just a set of variables and that's exactly what it is like literally it's just a set of key value pairs that we can turn on and have it applied to something to whatever right the I'm actually gonna do the example that I did the Amazon eBay we're actually gonna do it I mean we're gonna go through with it and um create a environment for Amazon and create Amazon I'm an environment for eBay and then be able to hots off between those two collection environments to run the same amount of requests the same series of quests the same collection of requests to search both websites based on the environment so on before we get into the environment though really quick let's go to a collection here I mean collections again I'm on my Amazon searches and then if I click this little arrow and and click run then I can actually run the entire collection okay which is just gonna run each of these one by one alright we have a bunch of different settings here I'm not gonna go over this right now let's just click run Amazon search collection and it's running it says little progress bar here 50% running one iteration no environment that's uh note that this is no environment here very important we're getting our responses back and it's almost done we're taking a little bit there we go and it's done so get all our results back run summary yada yada it's not we're not going over this right now but I just want to show you that you can run everything in a in a collection all the requests in a collection this is no environment so what we're actually going to do is we're going to create a collection of searches and then create different environments for depending on which environment we're running those searches in in our case it'll be Amazon eBay and then we can actually hot-swap those environments in and run the same requests with those different environments okay which is really cool because then we can create environments for maybe Google um shopping or any other searching shopping websites that all might exist so yeah let's let's start with just duplicating oops let's start with duplicating in this collection I don't want to get rid of it that's why so just go to duplicate cool here it is and now let's close both of these don't save and don't save whatever did it save those variables no it didn't that's cool though alright so let's go into here and now let's just change the name of this um to shopping website search cool and then oops actually searches okay cool and then here it'll just be we rename this to just iPhone so just iPhone this one's going to be just MacBook and then of course we can add more that we want whenever we want but we're just gonna do this and uh okay let's get started so um I think we should create the actually let's do this first let's just oh now I think we should create the new armor first let's go up here at the top left you can click this button and there's little window pops up environment we can click this or you can just click this little drop down menu and click environment here which is what we're gonna do so now the environment is just going to be Amazon Amazon okay and then for variables we can set all the variables one for this environment so what we're going to set is going to be I believe shop being website is think about I use before and then for us it'll just be Amazon calm cool and then also we're going to use search oh sorry actually don't need these in here silly me and then also we need search endpoint yep search endpoint and that will be just slash s and I guess we can put WWE don't need that screw it like that and then also search term and that will be K alright so as you can see we have amazon.com slash s and then we're gonna our parameters and it's going to be K and equals whatever it is and but then we have these nice variables here okay shopping website search endpoint and search term okay so let's just add all these all done here's our environment with the three things in there and now let's go back to here let's go to here and instead of Amazon we're going to use shopping website okay and then instead of search term I mean we're going to use search endpoint all right and then a set of K we're going to use search term all right and um yeah then iPhone stays because its host be iPhone so that is it let's send this it's probably not gonna work because we're not in the we don't have the environment set for it okay for this request which is okay but let's go and do the same thing for macbook so actually let's delete this one delete macbook and then just duplicate iphone duplicate and in here we will just rename this to macbook cool and then also we're going to just change this to macbook and that's pretty much it okay it's not gonna work again it's broken it didn't copy all this over all right copy that in just like that okay well I'd save this one I'd save on this one maybe that's why I didn't I'll duplicate correctly because I didn't save it alright so now that we have these two these two searches this is going to search for iPhones depending on any websites we have the website and then whatever search think we have to add on to it and then also the term that is required to search for an item on that website and we have the same thing for both which is cool but now now that we have this let's actually this collapse this let's actually set up an environment now that will arm well we already have the Amazon one set up so let's just run that okay so let's go to shopping website searches let's go to run okay and hopefully I typed in all of these variables correctly there's no typos let's go down to here so as you can see we have two searches to request your iPhone and MacBook with those variables in place and then if we just go down to environment and we select Amazon the one we just created um earlier and one iterations no delay you can set delays like between the searches I mean through the iterations like if you want to run on everything twice then you just put two iterations and then you could put like delays and whatnot but yeah let's just go there the main point was just environment you want to show you guys this and then when we run it you can actually see that the request that's actually being sent is amazon.com /s query parameter K equals iPhone okay and same thing amazon.com / s query search term equals Mac Book okay so everything's going correctly it's just a bit slow sorry this computer is not that powerful I should probably use the other one but it's not so bad alright cool so they both work correctly we got the green checkmarks and that was wearing the collection in with the Amazon environment so now let's create in ebay environment then we can see how we can use two different vironment for the same collection and run this collection over and over again depending on the environment we choose okay so let's go to here so new environment and actually I think if we just go to Amazon I think we can duplicate it is this duplicate or can we duplicate there we go duplicate perfect that makes it nice and easy it's not just going to here and instead of this we're gonna say eBay alright and then now now that we have all the same variables here now now I can't make any typos perfect we can actually change it so instead of amazon.com now we're going to have a bay comm of course all right update oops you better calm and then the search end point I believe for eBay I looked it up earlier the search end point is a little bit weird it's this ok it's not just /s like Amazon it's actually this alright and let's just pop those in there like that update and then last lastly the search term is also kind of funky it's ampersand underscore and kW whatever that means instead of just K but the point is that we're gonna put these in here like this update alright so now we have Amazon and eBay let's close out of here and now we have our commands here now if we go to this collection and we hit run and this time we can select eBay or Amazon and then run the file or run the collection then we can see that we are getting ebay.com / SC h / HTML and that one too and you can see that they both passed and it was it was filled out correctly because of the environment use but we were actually ran the same exact collection it's just with different environments okay so that's pretty simple like literally all environment is just a bunch of key value pairs let's go here again environment and you can just set them all and then you have a bunch of different vitamins and then you can you can like select these environments like if we're ho here in Amazon okay if you have this selected here well let's do a okay if we were in eBay and then um then we sent it let me go to preview then we can actually see that there was i phone searches in ebay here okay because we have it selected and same with macbook it is gonna behave the same exact way and there we go oh and I realized I didn't actually show swapping so really quick we had the eBay MacBook search here let's just run this again so running fresh and then all we need to do we see we have our macbook our macbook search results on ebay all we need to do is just hot swap to amazon the amazon environment and then running it again the same exact request we're just in a different environment and it'll load suddenly we are on amazon searching for macbook as well okay so that's the power of environments now we can you could add on like different technologies you could change to like oh technology website searches whatever and then have like iphones MacBooks i don't know i watches whatever Apple watches any anything else you want but yeah that's environment so you guys hey you guys so now we're gonna go over writing scripts and postman I've specifically pre request pre pre request scripts it's hard to say as you can see over here that I'm clicking on and I'm also tests you can write tests the difference between these two is we can both of them are scripting pretty much but pre request scripts will run before it runs the request and then tests run the tests both the response comes back so it's kind of like okay where we can edit the request here by um running scripts and then when the response comes back then we can run tests on the response to make sure um things are coming back as expected but right now I'm gonna go over just pre request scripts first um you can have this in many different levels you can write these at the collection level so it applies to like everything in a collection when you run a collection it'll run this script before every collection and every request and likewise with scripts I mean I'm like rise with tests that it'll it'll apply to all of the the entire collection that as you can see here I click on edit collection and there's also pre request scripts and eight um option here for collection so you can write it at the request level like I am right now per request or you can write the collection level and I believe you can even write it like other levels but we will just be focusing on this because it like if you understand one then you can apply it to all the different levels and it works just fine all right so let's let's go back to I'm in this collection right now with the environment we have the environment of Amazon and then we're running the the iPhone search term and let's just say I wanted to change some variables that's a very common thing to do in the strip's change some variables before we run the request okay so let's say we have like okay we have this whole thing here and we're searching for iPhones well I want to show you how maybe we could change that so like I mean obviously we can just go to the parameters and change this iPhone to Apple watch or something right manually right here but maybe we didn't want to do that maybe we want to like test it like on a different parameter or something like oh if if iPhone has no results blah blah blah or something or iPhone something and anything then you can just change it like on some parameter like basically you can you have full flexibility because you're just coding out here but I'm just gonna show you how you can get variables and set variables which is the most common thing you would do most basic thing you would do in pre request scripting okay so if you if we go to this upper end thing on the environments and then I click on Global's you remember that I set a global variable called my name and set it to my name Erin you know the current value is currently airing and this is all we're going to need I'm just gonna use this use this as demonstration purposes to show you how to do this so um we are in a pre request script for this request so what I want to draw your attention to is here on the right there are something called snippets a bunch of snippets here and pretty much what these do is they just allow us to it writes code for us automatically very easily so that we don't have to like code it all from scratch so as you can see we can get an environment variable we can get a global variable we can get a variable you can set all these variables we can clearing variables on all the stuff we can even send a request we can send a request within the script before we send this request and stuff like that as you can see like well it's going to this URL blah blah blah and then like just printing the stuff out to the console as when I clicked on it you saw that it auto complete which is pretty cool but we're just gonna use one just to show you you guys you can explore all of them yourself if you want but in this priam request script I'm just going to get a global variable okay well actually first let's comment that out this is a node GS I believe if I'm not mistaken so you probably need to know that to make you submit but not really because you can just use these snippets and kind of get it done and if you're not a program in general then you can kind of figure it out but let's just do console dot log first okay and let's just go hello world okay just to show you how this script will work we have this here and let me open my let me open a fresh postman console there we go and it's going and now it's empty but let's run this request okay go back here and as you can see hello world popped up in the console alright and before the request was sent you see how that works hello world was printed and then the get request was sent okay and then if we go back to postman we can see that yeah we look for iPhones and I was on cool now now um that we know how to print we printed hello world now I want to get I actually let me delete this if you guys forgot I want to get a global variable so I just click on this snippet and boom that's how I get a global variable remember I had the global variable of my name so it's this variable key every variable is a key value pair so what is the key of that variable well it was just my name like that okay now you can even see it autocompletes for you with the initial current and scope tells you global and then you just say my name and then we can actually print this out as well if we needed to okay so let's run this again go back to the console as you can see hello world printed out as normal but also Aaron printed out which is the global variable my name okay and then we sent the request because this is a pre request script so again we can do all these cool things you can also like like set variables within here cuz of course you can code you have full control over everything and go like this and then have variables in here and then you could like like check can be like if if my name equals Aron yada yada you know stuff like that or whatever however you want to type it all pretty much you can do anything you want in here I'm just showing you the the basics and then you're free to problem solved as you wish so that's how you can like set variables and whatnot and print them out in pre scripts um one more snippet I want to show you is actually setting so let's just set a global variable and now it says they're asking for the variable key so this is gonna be my name okay and the variable value I want to put it to my last name which is just Bernath alright so this is going to set so we have we're just gonna print hello world and then we're going to get my name which is gonna be Erin it's gonna print out and then actually let's close this so that doesn't get confusing let's open up a fresh one this is irrelevant I'm just showing you how to how to save a variable I'm going to delete that and then then we're gonna set it and then we're gonna do it and then we're gonna print it again alright just like that so right now the global variable is iron right there as you can see and the postman console is empty and let's hit Send on this get request wait for things that come in as you can see hello world popped up okay Erin and then Erin popped up because we printed it out and then we set the my name Google variable to Bernath and then printed the burneth variable the my name variable again which is verrat my last name and then it sent the get request okay and actually if we go up here to global variables we can see that the the value of the global variable is actually changed okay so that is pretty what you can do in pre request scripts I mean you're able to basically modify all of the variables like if you want to modify these environment variables instead of as we're in the Amazon environment variable right I mean we're in then we're in the Amazon environment right so we I could actually go in and get these variables out like Amazon calm and slash s and K and stuff and I'm going there and actually change those just by calling these things like get an environment variable PM stands for post mates in case you're wondering PM post mates dot blah blah blah or postman not post mates I guess I'm getting hungry and then set environment variable to same deal and then regular variables of course so that's kind of the general idea maybe like you wanted to be able to change the iPhone thing like I mentioned earlier like you like basically you're able to just use code to do whatever you want with the request so you have like full control over all of it okay so that's pure um request scripts um now we're gonna get into testing which is very similar alright so testing so writing test scripts like I said earlier is testing the response that we get back from a request okay so we are going to try that now so I found a different API here other one was giving me a little bit of trouble with it um but this one's cleaner and easier the JSON is is just cleaner so we're gonna use this one let me just run the command so you can see what it looks like it's HTTP rec rests which is probably request response NDP I've at slash users it's just like a dummy API that we can use there's some nice JSON here very similar to what you're using before but um yeah so now let's write a test let's just go straight here and just start reading it so this is the response we get back okay as you can see there's a bunch of different stats here like the status 201 okay and then time I took in all that stuff from the size of it but if you go to the snippets here it's actually a little bit different than the pre request script if you go to pre request script we can see there's only a few here but if you go to tests then there's a bunch there's a bunch of different ones ok so let's just go through some of them and I explained the most common ones and some useful ones obviously we can get environment variables and global variables just like we did before environment variable like we're currently in the Amazon environment so if we looked up if we looked up like the shopping website or something like that let's take a look if we looked here if we type in any one of these we get the value out okay same thing we can actually set those from here if we wanted to after the tests came back so maybe like if the response came back and then we did find something we did find a term or whatever above what like we found what we're looking for then we could like change them with the variables and run another request and like chain them together like that but that's not what we're doing right now um you can again it send a request but here's one that is immediately catching my attention that's pretty simple and easy to understand status code code is 200 so if I click this ok this pops up it says postman dot test status goes 200 and then I just make sure that the status is 200 so when we ran this we got a 200 ok so let's just try to send this again and see what happens ok if we go to test results it says there was no test for this request but now if we go run this again ok with this test in place as you can see test results now has 1 out of 1 so let's go to test results 1 and then as you can see it's as it passed because status code is 200 because status code was 200 ok but let's say we were checking for let's say we type in a bogus URL okay so like I'll just type in a bunch of F's here this URL I don't think exists when I run this then maybe it does exist or something hmm I'm trying to get it to fail here we go send API slash users slash ten or something come on just give me a just give me a four for when I need the four or four area um air it doesn't pop up oh my goodness alright well the point is if I was getting a 404 error then this would feel actually let's go like this okay did this will demonstrate what I'm trying to demonstrate let's just go to there we go test result failed so the check we're making was we wanted the status code to actually be 404 we're trying to make sure that it is 404 and that's when it is considered passed so since we got a 200 this is actually considered to fail so it says fail status code is 404 the expected the status code 404 but got 200 which is kind of a funny thing to check for but that's just demonstrating the idea okay so that's testing results pass and fail and also when we run collections like these test results come in handy because when you run the whole collection then all the tests will to come back together which is nice okay but let's change this back to 200 okay because that's the proper functionality and let's just keep going down a few more so we can check for code is 200 what else responsive body contains string so let's let's do that okay so contain string let's just click on this and then we're just making sure that there's something in here is um is there so let's just grab Janet okay and then just like pop this in here like that hit send again and as you can see boom now we have test results two out of two and it says body matches string okay which is because Janet here is there however though if we put um Janet with a double tee then or I don't know let's put like Jackson instead we're looking for Jackson inside here which is not there and we hit Send then we fill obviously okay so as his body matches string I'm expected to see Jackson but it didn't see jacks it's pretty much what it's saying alright but of course we can put that we can put Weaver this should pass again because was Weaver right there that'll pass yep and that kind of explains that one okay but now we are starting to get some more interesting things so um the others also on here response time is less than 200 milliseconds this would be useful if like we wanted to make sure that our website is really fast or something like make sure it responds quick enough you know amaz almost taking kind of a long time okay like we could run like some tests in here and be like oh if response time is more than 200 then something's wrong blah blah blah display something pretty much anything we can just like test for the amount of time but I mean this is 200 but we can send it to a thousand if you wanted to we can put it to anything we want all right but let's just put 200 and run this as well we should have three passes cool and um now let's uh instead of just looking at just one and see what all the users we get the whole thing and again we have all the passes because of course that Janet data was inside the entire thing so it still passes but now now let's say where it gets interesting is or another one is you can like check the content-type header so like okay make sure we're getting JSON back our mate make sure we're getting HTML back or make sure we're getting an image back or something you can kind of like specify the content time but you're getting just like enforce that you can check that out if you want but we're just gonna check this last one here it's called JSON value check okay so this one is cool because oops because it allows us to really dig into the JSON data and then we can really check things in like and make sure that things were correct like if we posted something to an API and we created it and then we went to I share it posted correctly when we get the response back we can like dig into the JSON response and whenever it makes sure like it was right and this in that like oh I'll make sure the post request was successful like actually here there's another status code request to make sure that the that the on post request was successful because 200 is for get requests right mainly forget requests it's like okay - um status code 200 I found the web page here it is but - um anything 200 is good but 201 and 202 I believe is if you post something it's like oh yeah we posted it it's good here's a response blah blah so I mean you can do that there's a bunch you can check them all out if you want but this Dom we're just gonna continue don't want this one so sorry so here um what's going on here is we are getting the json data back in the response so the postman response object we are converting it to a json file or json object with the json and then we just get json data here saved in a variable okay and now that we have json data we're able to just use dot notation to dig into any of this json that we want pretty much okay and then we could just say oh whatever data is in the json it needs to equal something and then we can use that as tests in assertions okay so let's just try this so json data so the first thing we have is page let's try page so because jace we have json data which is this here this bracket here then the very first thing is page the very very first level um this page so we can actually do this and this should should equal one so when i hit send there should be a fourth test and it should be passing oops oops i don't know what the issue is oh there we go I think that was the issue all right there we go I had a typo there so test results um the the page does equal 1 but like if we put maybe 2 here which is not equal then they should actually fail and as you can see yes it does fail because page the page thing here in this JSON is supposed to be 1 not equal to 2 but let's say we wanted to dig down like really deep like arbitrarily deep let's dig back down to jannat again okay ID 2 and just let's just make sure that her um her last name actually is Weaver or something like that okay make sure her last name is Weaver so how will we do that is okay we have our JSON data here you guys probably already figured this out if you know how to code but just I'm just gonna follow I'm just gonna follow through for a completeness sake but we're not gonna go to page we're gonna have to go to data which is also the first level so we can go directly to it but then once we're in here then we have a list all right so we have a list of JSON objects in here itself so we want to find Janet so this is a 0th one this is the first one so it would have to be indexed at zero data now we're in here okay and now we just keep using dot notation and we want last name right so now we just type dot last name our last name and now this should equal Weaver okay so I'm just gonna copy this and I'm going to pop this in here just like that but make sure it's a string okay because it's a string type and hit Send and this test result should come back is pass and apparently not let's see what the issue is oh because the okay this one let's say 500 less than 500 now we should all have a pass make it a little bit easier on us okay so actually this previous test field that wasn't the one that we just did so pretty much this is working as intended we're saying okay if the JSON data they'll be digging down below blah blah of this key if the value is equal to this then we consider pass if not like um if we put like huazi cool I don't know what that is but if we use that then it would fail okay you would say that the certian air Weaver but was expecting huazi all right so that is how you run test scripts in postman for your response objects um or from your HTTP responses or whatever you want to call it you can also run these at the collection level just like you could with the pre request scripts as well okay so when you run the entire collection then all these tests will be run after it and again you can you can make variables in here as you can see JSON data right here and you have full control over everything in the code with within your request any responses to really test anything you could imagine pretty much okay but I gave you all the basics that you guys need now it's your job to go out and actually apply these things to figuring out how to use postman to solve whatever problem with the API as you're trying to solve okay but that's pretty much it for scripting pre request scripts and tests and I'll see you guys in a few seconds to go over on the next thing alright you guys so now we're gonna go over pretty much the last thing in this postman crash course and that is setting up mock servers all right so I mentioned this a lot at the beginning of this crash course we kept saying old mock server this mock server that that's because up to this point we've been doing a lot of client stuff so we might have been working on or creating like dummy client arm requests so we can like create basically any client request we want and then we can send it to any existing API that or you exists and then get something back ok so we had flexibility around shaping what the client was happening with the client but the API is had to already be there in place now mock servers will allow us to do the flip flip option of that let's say the API doesn't exist okay maybe we're developing a client and a server for a client or something and both things need to be developed but the server doesn't exist but we need to build the client like one of them needs to exist to be able to test it so we are able to UM work on the server and then send mock requests to the server using postman which is what we've been doing up to this point we can just create whatever quests we want and paying the server but let's see we're all working on the client-side and we need to send requests somewhere and get a response back but the server doesn't exist yet okay if the server doesn't the API doesn't exist then we need still need somewhere to test it so that's where mock servers come in we can create mock servers which basically says oh if there's a request to this URL - yeah - this specific URL on the server then reply with this we're basically gonna be hard coding in responses to specific requests so like if it's if if like oh this specific request ins with these specific headers and this specific URL and all this yada yada comes in send back this specific response be it JSON or HTML or whatever kind of data were sending back the entire response object with its own headers and everything so it's kind of an overview of what we're gonna be doing now we're actually going to postman and go through actually doing an example with this you can see see how it's done and maybe understand it a little bit better so let's first start with creating a new collection okay so you need a box server I mean we need a collection to create a mock server because every mock server has a collection associated with remember a collection is just a group of requests and that kind of makes sense because we need a mock server up and running and then we're gonna have a bunch of requests that can be sent to that mock server and it's just nice to have all of those requests together in a collection okay so I'm gonna call this mock server requests name of this collection because this is gonna be when she requests going to the mock server and let's hit create so that's done but there's zero requests in here so let's just add one request really quick and we're just gonna call it request one alright so this is gonna be request one and um we just need a after we're done creating this request basically we're gonna have to have on the mock server know what to reply when this requests one specifically this request one comes in so let's just create request one there nice so we have a collection we have the request that we're gonna send to the mock server and now we actually need to setup the actual mock server within um that's associated with this collection with this collection so we hit this little button here and if you go over to the right here on this tab it says mocks and it says this collection is not being mocked okay a mock lets you simulate endpoints and their corresponding responses and collection without actually spinning up a back-end so that means yeah if the back end doesn't exist then we can simulate endpoints and points are just URLs pretty much like the path like oh if you reach this certain URL path then um then do something respond with something so let's just create um click create mock uh create a mock server and now we're just going to create a mock server so we're just gonna call it mock server all right very straight for I'm create a version tag this a little bit Vance we don't need this right now she's saying if this server is going to correspond with a specific API version maybe we're actually working on a new version of an API instead of like creating some from scratch and then we have to have a version yadda yadda but those are details that only matter when you're actually doing them and then also you can have environments um I'm just gonna click no environment but you can choose to import all the environments for this mock server so that all the variables that you have in that environment are already existing but we don't need that now either and they make this mock super private we could if you want but then you'd need a API that occation key and all that stuff and we're not gonna set that up right now so we're just gonna keep it public so let's create and create the mock server and that was pretty easy right it says mocks ever created we are done and I'm all you have to do is to call them mock server is just go to this URL alright this URL right here in orange and pretty much what this is saying is ok this is your mock server so when you go to this URL anything that comes after this like treating this as a domain and it comes after this can be um created as a mock server API so like ok if you like ok slash users or something um this slash users then you were gonna have to need to send something back basically this is just standing in for the domain maybe if we had an API in the future like this would act like if we were actually working on a project that needed a server using PHP or whatever server code you want to use or Django or flask or whatever then it would be like okay WWE my server calm slash API or something instead of this here but this is just a standard alright so on that little URL is right here it pops in as you can see now when we go to mocks then the mock server is here and there's a URL associated with it which is pretty cool so we're basically saying when you reach this URL then we are now integrating acting with our mock server so now we can start creating hard-coded responses to specific requests so if you click this button it's gonna copy the mock URL all right and now we're gonna go to the request ok let's close on with these tabs we don't need these anymore all right so now we have the request open and let's just pop in the mock server base URL okay the very base one the domain and nothing else let's hit Send and see what happens and as you can see this thing pops up okay this is the response we got so if we're writing if we run a get command just to the base mock server URL that we have then we get an error back and it says mock request not found error as in whatever's associated with this there was no response associated that we didn't find and the message says this collection does not have any examples um an example of something we're about to create it's a thing in postman right up here on this top right we're just about to talk about it but it says this collection does not have any examples please examples to the requests in this collection to enable mocking okay so all an example is is just the response we're gonna send back for a specific requests so so we're basically gonna say um well let's just go here up the examples okay it says no examples added save responses and associated request examples so we're just gonna click add example okay we get this new tab as you can see over here if this says get this is a request and then if we go here this is an example it actually says ie um eg dot which is a Latin abbreviation for example for example I think it's like or go something but it doesn't matter but so this is an example tab and now we can see that this example is actually set up so if when we were when we sent our question we got this response and the cool thing is that this response is exactly the same as what this response down here is okay that's because we're saying oh when we hit when we're in this example we're saying well we hit this and we hit this URL with these parameters and these headers and this body in other words anything the example requests up here anything in this white box whatever um this is specified exactly whenever that exact thing comes in to our mocks server then give this exact response okay so this is the base mock server and if we send that with note with no path coming after it with nothing after it at all and nothing else in it at all send back this JSON data with a 404 not found status okay and then have all the headers and stuff - okay this is JSON and this is clearly JSON so let me go back to the request and we send this again that explains why we're getting this okay sent that's what we're getting this like everything this is actually an error that was Auto created by postman now let's say we actually typed in something crazy like like whatever a bunch of stuff and then we hit Send um then we get the same issue um I think postman is just like autocomplete into whenever there's something doesn't exist then this pops up which is very handy but what we want to actually do is create a new example or did I save it what we actually want to do is create a example for um maybe another endpoint another URL so we can actually see how that would go now okay so let's go let's just duplicate this to make it clear so duplicate this and we are going to rename this to request to okay and copy that in there and then we're just gonna say users okay and then here this example well actually we can just go back up here and just create another example and then we're going to call this response - all right so we request one response one which was just a base and we're getting back this error and then now we're doing a request to in response to so now I actually want to add in something different so if we actually reach this um URL endpoint the mock server or base domain + users then I want to reply with something different okay so here we have it filled out on parameters I'm just gonna keep it light it makes sense it should be pretty straightforward that you can put in whatever you want here okay but I'm just gonna keep it empty because that's unneeded so we're just saying when we hit this URL end point then send a 200 okay response and then let's send um you could just send raw text so it could be like okay hi whatever but let's just send back JSON data so let's check JSON data as you can see you can send back XML or HTML or anything but let's just send back JSON data and it says slash users so let's um let's just make some dummy JSON data okay so this is gonna be the hard-coded response that we're gonna have to this very specific request and then let's just say um users like that and then we just say like name is Erin and ID is one cool and then let's just do the same thing um there we go but let's change this to name is cause II and ID is - okay very straightforward so I just create some dummy JSON here as a response so now we're saying on this mock server whenever somebody goes to this mock server um slash users then reply with this JSON data okay this JSON data with the 200 okay response okay and I think we need to actually say some of the headers too so let's just go into here other one and um maybe just copy all these or let's just run it and see what happens okay so let's run this alright guys so yeah I don't know why I wasn't getting the correct one maybe I didn't save it or something but now it's working so I created this this hard-coded respond to this JSON down here like we just did a few seconds ago and now um I go into this slash users in point URL and now when I go to request um to and I go to that same exact URL at the same endpoint slash users and I hit Send then it works as expected I didn't change anything okay um I don't know what it was I think it was yeah I just don't think I saved but if we view this as JSON then you can see that the response we get is exactly what we said the example should return we said example should return this stuff if we go here and when we actually go there on a request that's what we get back very very straightforward okay um originally I thought it was because all the headers weren't there but we don't need all them but I mean we can fill it out if you wanted to all these headers here the easiest way to just be like I actually duplicate this other one that has all of them in there um here and then all the headers already there and then just copy and paste all of this code this was JSON response instead and to here like this okay paste that in and then let's just actually call this response 2.5 and um say slash users I guess we're doing this really quick and save that ok should be saved users yep um and let's just put Aaron 2 in Kazi 2 just so we're aware that it's the right one a little difference in the response so that's saved let's just let's just delete this one I guess response to it delete and there we go so that doesn't exist anymore now this example should be associated with this endpoint so now we go to this endpoint again and we hit Send then as you can see Aaron - and Kazi to pop up which is the change we made and all the headers are there okay which is that once we copy it over so as you can see it autocompletes to json before remember it was just like Oh autocomplete comm HTML and it was looking kind of ugly that's because we didn't have the content type set to JSON and stuff because there is no headers and some of these headers are are mandatory by good practice pretty much but that really simplifies things if we just copy over all of the headers from the original example okay over here and that's pretty much it you guys for mock servers so you're able to create a collection with a bunch of requests in it and then you have a mock server base domain associated with that collection and then all the requests you send to that domain can be given hard coded responses by creating examples okay and that's pretty much the overarching logic of it very simple just remember that and you guys can pretty much set up any mock server you want so any request that comes in you can specify exactly what you want to get sent back so it makes it very easy for developing client-side servers or client-side API s and whatnot so that should be it for the post in crash course pretty much thanks you guys for watching hope you guys learn a bunch and I hope you guys have fun playing around with the API is whether it be your own or ones you find on the Internet yourself there's a lot of cool ones out there but yep that pretty much wraps it up you guys good bye hey what's up you guys so if you'd like that video if you have an epic three-part free master class that teaches you how to go from complete zero to becoming a six-figure freelance developer with Python if you want to check it out they click click the link below in the description there should be a place where you can put in your email and your phone number and your name and you can sign up and you can get direct access about it there's a lot of free value there just go check it out I think you'll really like\n"