Skip to content

Instantly share code, notes, and snippets.

@wolivera
Created August 5, 2021 16:21
Show Gist options
  • Save wolivera/a418a1be322116f271643a78a0171b99 to your computer and use it in GitHub Desktop.
Save wolivera/a418a1be322116f271643a78a0171b99 to your computer and use it in GitHub Desktop.
Jokes API Postman Collection
{
"info": {
"_postman_id": "267cb468-eb06-4021-9743-6ba3b0c2139d",
"name": "Jokes API",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "GET Random Jokes",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"pm.test(\"The response has all expected properties\", () => {",
" //parse the response json",
" const responseJson = pm.response.json();",
"",
" pm.expect(responseJson.type).to.eql('success');",
" pm.expect(responseJson.value).to.not.be.empty;",
" pm.expect(responseJson.value[0].id).to.be.a('number');",
" pm.expect(responseJson.value[0].joke).to.be.a('string');",
"",
" pm.collectionVariables.set(\"jokeId\", responseJson.value[0].id);",
"});",
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{jokesApiUrl}}/jokes/random/4",
"host": [
"{{jokesApiUrl}}"
],
"path": [
"jokes",
"random",
"4"
]
}
},
"response": []
},
{
"name": "GET Random Joke by Id",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"pm.test(\"The response has all expected properties\", () => {",
" //parse the response json",
" const responseJson = pm.response.json();",
"",
" pm.expect(responseJson.type).to.eql('success');",
" pm.expect(responseJson.value).to.not.be.empty;",
" pm.expect(responseJson.value.id).to.be.a('number');",
" pm.expect(responseJson.value.joke).to.be.a('string');",
"});",
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{jokesApiUrl}}/jokes/{{jokeId}}",
"host": [
"{{jokesApiUrl}}"
],
"path": [
"jokes",
"{{jokeId}}"
]
}
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
],
"variable": [
{
"key": "jokesApiUrl",
"value": "http://api.icndb.com"
},
{
"key": "jokeId",
"value": ""
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment