HTTP servers Flashcards

1
Q

Processing HTTP requests with Go is primarily about which two things?

A

Handlers & Servemuxes

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

What are handlers fairly analogous to in MVC?

A

Controllers

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

Generally speaking, what are handlers responsible?

A

Carrying out your application logic and writing response headers and bodies.

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

What is a servemux also known as?

A

Router

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

What does a servemux store?

A

A mapping between the predefined URL paths for your application and the corresponding handlers.

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

How many servemuxes do you usually have?

A

One, containing all your routes

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

Which Go package ships with the simple but effective http.ServeMux servemux?

A

net/http

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

Which servemux is available from the net/http package?

A

http.ServeMux

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

The net/http package has functions to generate common handlers. Give 3 examples.

A

http.FileServer(), http.NotFoundHandler() and http.RedirectHandler().

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

Which function creates an empty servemux?

A

http.NewServeMux

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

What parameters does http.NewServeMux take?

A

None e.g. mux := http.NewServeMux()

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

How would you create a handler which 307 redirects all requests it receives to http://example.org?

A

rh := http.RedirectHandler(“http://example.org”, 307)

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

How would you register a handler, rh, for all incoming requests with the URL path /foo?

A

mux.Handle(“/foo”, rh)

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

What does the http.ListenAndServefunction do?

A

Creates a new server and starts listening for incoming requests

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

What parameters does the http.ListenAndServe function take?

A

A port specification and a reference to our servemux e.g. http.ListenAndServe(“:3000”, mux)

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