Lecture 9 Flashcards

Request/Response cycle, response status codes, GET and POST requests, APIs, making get requests, JSON response

1
Q

what is DNS? (2)

A

1 domain name server

2 the process through which human-readable domain names (www.digicert.com) are translated into a computer-readable IP address (216.168. 246.55)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Explain the request response cycle

A
  1. computer makes a request from the server
  2. server processes the request
  3. server issues a response
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Response status codes (4)

A

2xx - Success
3xx - Redirect (example we get directed to google.com without a www)
4xx - Client Error (your fault!)
5xx - Server Error (not your fault!)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what are GET and POST requests

A

GET is used to request data from a specified resource

POST request - Useful for writing data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what is a post request? + example

A

POST requests can transmit data of any type

Example of POST response is posting a photo on facebook.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

API

(4)

A

1 Application programming interface
2 Allows you to get data from another application without needing to understand how the application works
3 Can often send data back in different formats
4 Examples of companies with APIs: GitHub, Spotify, Google

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

request module + syntax

A

allows you to send HTTP requests in Python

!pip install requests

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

requests get method (3) + syntax

A

1 retrieves information from the server using a given URL. The GET method sends the encoded user information appended to the page request.

2 The page and the encoded information are separated by the ‘?’ character.

3 not suitable for sending sensitive information

requests.get(url, params={key: value}, args)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

ok method + syntax

A

returns True if status_code is less than 400, otherwise False

x.ok

where x is a variable containing a get request eg

x=requests.get(url)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

.text method

A

returns the content of the response, in unicode. Basically, it refers to Binary Response content. (???)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

headers ()

A

1 HTTP headers let the server know additional information about the reqeuest

2 All the headers are NOT case-sensitive

3 headers fields are separated by colon, key-value pairs.

ex: Headers = { “Authorization” : ”our_unique_secret_token” }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

.status_code method

A

returns status code of a get request

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what does the headers argument do in the response module?

A

import requests
url = “https://icanhazdadjoke.com/search”
response = requests.get(url, headers={‘Accept’:’text/plain’})
print(response.text)

headers={‘Accept’:’text/plain’} This argument returns a plain text version.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

JSON (2)

A

1 stands for JavaScript Object Notation.

2 Python can convert it very quickly to a valid python code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

why do we want json. in dictionary form and how do we do it?

A

prints the JSON data in the Python dictionary format as seen in the output.

In this way, we can parse JSON responses in Python. and access them via dictionary format.

syntax: x.json()

where x is a variable storing a get request

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What’s a Query String?

A

1 A way to pass data to the server as part of a GET request

2 A query string is a set of characters tacked onto the end of a URL.

3 The query string begins after the question mark (?) and can include one or more parameters. Each parameter is represented by a unique key-value pair or a set of two linked data items. An equals sign (=) separates each key and value. An ampersand (&) separates multiple parameters.

17
Q

define endpoint

A

endpoint is a specific location within an API that accepts requests and sends back response

18
Q

what is unicode?

A

(eg the Unicode Standard) is a universal text encoding standard maintained by the Unicode Consortium designed to support the use of text in all of the world’s writing systems that can be digitized

19
Q

what is a payload?

A

a data package that is sent between a client and server in a web API.

20
Q
A