Able to demonstrate how to create an HTTP request Flashcards

1
Q

Example HTTP Request

A

.

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

Example HTTP Request POST

A
  • The method parameter specifies the HTTP method to be used for the request.
  • The headers parameter specifies additional information about the request, in this case, it’s specifying the content type of the request body as JSON using the ‘Content-Type’ key.
  • The body parameter contains the actual data being sent in the request, which is a JavaScript object ‘data’ that is converted to a JSON string using the JSON.stringify() method.
    • When sending data in the body of an HTTP request, the data must be sent as a string.
    • The JSON.stringify() method is used to convert the data to a JSON string so that it can be sent in the body of the HTTP request.
  • Accept: used to indicate the expected response format (e.g. JSON, XML, HTML, etc.)
  • Authorization: used to provide authentication credentials for the request
  • User-Agent: used to identify the client making the request (e.g. the web browser or device being used)
  • Referer: used to indicate the URL of the page that linked to the current page (typically used for tracking and analytics)
  • Cache-Control: used to specify caching behavior for the response
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

promise

A
  • A Promise is an object in JavaScript.
  • When you make an asynchronous operation such as an HTTP request using fetch(), it returns a Promise.
  • This Promise is initially in a “pending” state, meaning the operation has started but the result is not yet available.
  • Then the operation completes, the Promise either
    • resolves with a value (e.g. the response from the server), or
    • it rejects with an error.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

asynchronous

A

asynchronous means the operation can be started and running in the background, without blocking the execution of the rest of the code.

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