Concurrent API Design - 6.4 Sending HTTP requests Flashcards

1
Q

What are the steps involved in sending a request an reading a response using the http package?

A
  1. The Do method sends a request using a Request value.
  2. It receives a response as a Response value. The Response type represents a response from an HTTP request and contains details such as status code and body in a field called Body.
  3. You can use the Body field to stream the server’s response.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is io.Reader?

A

The Reader type is an interface that can be used to Read a stream of bytes from any resource.

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

What is io.Writer?

A

The Writer type is an interface that can be used to Write a stream of bytes to any resource (such as file or memory).

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

What is io.Discard?

A

Discard is a variable that implements Writer such that all Write calls succeed without doing anything.

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

What is io.Copy(dst, src)?

A

Copies from src to dst until either EOF is reached on src or an error occurs.

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

How many connections does http.DefaultClient keep open and how many are allowed for reuse to the same host?

A

100 connections can be opened.
2 can be reused to send to the same host.

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

What is http.Transport?

A

This is the Transport type. The transport establishes TCP connections, sends HTTP requests, and has a connection pool to store idle connections.

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

What is the http.Client?

A

The Client type provides a nice API and allows you to send HTTP requests, handles cookies, and redirects.

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