0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
click for more info
No active XP Potion
Accept a Quest
Login to submit answers
The Go standard library has a lot of powerful HTTP features and, as of version 1.22, comes equipped with method-based pattern matching for routing.
In this lesson, we are going to limit which endpoints are available via which HTTP methods. In our current implementation, we can use any HTTP method to access any endpoint. This is not ideal.
There are powerful routing libraries like Gorilla Mux and Chi, however, the course will assume you are using Go's standard library. Just know that it isn't your only option!
Run this command to send an empty POST
request to your running server:
curl -X POST http://localhost:8080/healthz
You should get an OK
response - but we want this endpoint to only be available via GET
requests!
Using the Go standard library, you can specify a method like this: [METHOD ][HOST]/[PATH]
. For example:
mux.HandleFunc("POST /articles", handlerArticlesCreate)
mux.HandleFunc("DELETE /articles", handlerArticlesDelete)
When a request is made to one of these endpoints with a method other than GET
, the server should return a 405
(Method Not Allowed) response (this is handled automatically!).
Run and submit the CLI tests.
The Boot.dev CLI requires you to be signed in to submit your solution!
Copy/paste one of the following commands into your terminal:
Run
bootdev run d1c4962d-f55e-4f0f-ac9c-913db8ef8ae8
Submit
bootdev run d1c4962d-f55e-4f0f-ac9c-913db8ef8ae8 -s
bootdev config base_url <url>
Run the CLI commands to test your solution.
Login to view solution
Using the Bootdev CLI
The Bootdev CLI is the only way to submit your solution for this type of lesson. We need to be able to run commands in your environment to verify your solution.
You can install it here. It's a Go program hosted on GitHub, so you'll need Go installed as well. Instructions are on the GitHub page.