web application basics Flashcards

1
Q
  • What is the purpose of the net/http package?
A

It provides HTTP client and server implementations for building web applications in Go.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  • How do you start an HTTP server in Go?
A

By using http.ListenAndServe with a specified address and handler.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  • What is a ServeMux in Go?
A

It is an HTTP request multiplexer that matches the URL of each incoming request against a list of registered patterns and calls the corresponding handler.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  • How do you register a handler function for a specific route in Go?
A

By using http.HandleFunc with the route pattern and handler function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  • What is the purpose of the http.ResponseWriter interface?
A

It assembles the HTTP server’s response by writing header and body data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  • How can you serve static files in Go?
A

By using http.FileServer and http.StripPrefix to handle requests for static assets.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  • What is the role of the http.Handler interface?
A

It defines a method to serve HTTP requests and is implemented to create custom handlers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  • How do you implement the http.Handler interface in Go?
A

By creating a struct with a ServeHTTP method that takes http.ResponseWriter and *http.Request as parameters.

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