Begin Training - Requests
Let's Start with our Collections.You can understand request as per the word says that you are requesting data from the server.
- For starting learning you need to click on SEND which means you are Sending a request to given route ( URL ) which is "postman-student-expert.glitch.me/training" in this case as you can see there.
- When send the request you will get response
- In this collection response will help you to do next steps
This Particular Request will teach you how to setup a variable
- You need to select the "postman-student-expert.glitch.me" After hovering the selected area you will be able to SET AS VARIABLE.
- For setting up variable you need to provide name "training_api" and scope as Collection.
- When you need to use the url "postman-student-expert.glitch.me" for sending request you can now use .
- For eg: "/matches"
- With this note let's move to next request in our Folder which is GET MATCHES ! Don't Forget to SAVE THE REQUEST from top right area in Navbar.
GET REQUEST
GET /matches
- When you send the request you get data about matches. You can also read more in VISULIZE
- Our first task is to get the matches with status as pending. We can do this with help of query parameters
GET /matches?status=pending
- You need to send this route.You will get the matches which are pending as a response.
- This is how you can sort data coming from API ( The sorting must be provided by the server also. )
- You need to save this request and create a new request "2. Add match
POST Request
- You need to send a POST Request now
POST /match
- This will give you authentication error because we need to be authenticated to get some response for this request. You can understand auth as login to account.
- Click on three dots near collection name and this will give you option to edit then click on that.
- When you see under authorization you can see key as matchkey and value as emailkey which means you need to provide your email as emailkey
- We need to create a varible with name emailkey and value as email we used for registration.
- Click on variable tab and create a new variable under training_api.
variable : email_key
initial_value : rohank2502@gmail.com
- Now after sending requst it will give you Bad Request - Check your body data because in POST request we need to provide some data in body.
- Click on BODY then Click on TEXT and convert it to JSON
- Add the given object in the body and send request again.
{
"match": "Cup Final",
"when": "",
"against": "Academical"
}
- This time you will see SUCCESS MESSAGE. You can check about the added data in get matches request.
- Now next step is PUT Request.Save this request and create a new request "3. Update Score"
PUT REQUEST
PUT /match
- When you send this PUT request you will get an error which will ask you to provide match id.
- You can go to GET request and then send it again and copy the match id of the match you added ( ONLY MATCH YOU ADDED CAN BE UPDATED BY YOU )
- You need to provide this id as params
PUT /match?match_id=LwDlF-mHt
- Your request will look like this.
- This reqeust will give you error becuase in PUT requset you need to send data to be updated in body
- Go to body select raw and type as json
{
"points":3
}
- Send this Object as JSON
- You will get a success message now. Next Task is to DELETE the match.
- Don't forget to save this request and create a new request "4. Remove match"
DELETE REQUEST
DELETE /match/:match_id
- You need to pass this request in DELETE and this will delete the match with this id. ( YOU CAN ONLY DELETE THE MATCH YOU ADDED )
/:match_id
- This is a PATH Variable which will help to know which match you want to delete.
- That's it for this part and you will save the request and move to the next part.