softacoder / Coursework-Planner

Your coursework planner
0 stars 0 forks source link

[TECH ED] Call an API #113

Open softacoder opened 1 year ago

softacoder commented 1 year ago

From Module-Node created by Dedekind561: CodeYourFuture/Module-Node#6

Link to the coursework

http://api.tvmaze.com/shows/82/episodes

Why are we doing this?

This task will get trainees to really think about the response you get back from an API. In addition, it will encourage trainees to use Chrome Dev Tools to examine the response you get back from the server.

Look at a request in Chrome Dev Tools In Google Chrome, open dev tools network tab and enter this URL into the browser: http://api.tvmaze.com/shows/82/episodes

Answer the following questions: What's the status code the server sent back? What HTTP method did the browser use to make the request? What is the request path? What is the first line of the response body? What is the value of the response header called "Content-Type" ? What is the value of the request header called "User-Agent"

Maximum time in hours

2

How to submit

Share your answers with the other trainees in your Buddy Group or on your Slack class channel. Did you get different answers to other people? Ask them how they worked them out!

softacoder commented 1 year ago

What's the status code the server sent back? Failed to load resource: the server responded with a status of 404 () I found the answer by checking the console. I can also dig deeper by going to console and tick in LogXMLHttpRequest and then go to network and here I have status 304 on episodes, viewer.css has status 200 and CircularXXWeb-Book.woff2 has status 200.

What HTTP method did the browser use to make the request? All three mentioned above have GET. You find this out by clicking on their titles.

What is the request path? I found this help. https://stackoverflow.com/questions/58614864/whats-the-difference-between-httprequest-path-and-httprequest-pathbase-in-asp-n#58615034 So my answer would be: /shows/82/episodes

What is the first line of the response body? While I am in network i change from header to response. When i check episodes first line I get: [{"id":4952,"url":"https://www.tvmaze.com/episodes/4952/game-of-thrones-1x01-winter-is-coming","name":"Winter is Coming","season":1,"number":1,"type":"regular","airdate":"2011-04-17","airtime":"21:00","airstamp":"2011-04-18T01:00:00+00:00","runtime":60,"rating":{"average":8.1},"image":{"medium":"https://static.tvmaze.com/uploads/images/medium_landscape/1/2668.jpg","original":"https://static.tvmaze.com/uploads/images/original_untouched/1/2668.jpg"},"summary":"

Lord Eddard Stark, ruler of the North, is summoned to court by his old friend, King Robert Baratheon, to serve as the King's Hand. Eddard reluctantly agrees after learning of a possible threat to the King's life. Eddard's bastard son Jon Snow must make a painful decision about his own future, while in the distant east Viserys Targaryen plots to reclaim his father's throne, usurped by Robert, by selling his sister in marriage.

When i check viewer.css first line I get: .CodeMirror { The third has nothing.

What is the value of the response header called “Content-Type” ? In viewer.css i find content type. The answer is Content-Type: text/css. In CircularXXWeb-Book i found Content-Type: application/octet-stream

What is the value of the request header called "User-Agent"? I found this by having network and the headers chosen under the title Request headers: My answer is User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36