Skip to content

Commit

Permalink
Merge pull request #20 from gossie/gossie-patch-1
Browse files Browse the repository at this point in the history
Update README.md
  • Loading branch information
gossie authored Mar 25, 2024
2 parents c7c444f + 283f468 commit d81f719
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ func main() {

httpRouter.Get("/books", getBooksHandler)
httpRouter.Post("/books", createBookHandler)
httpRouter.Get("/books/:bookId", getSingleBookHandler)
httpRouter.Get("/books/{bookId}", getSingleBookHandler)

httpRouter.FinishSetup()

log.Fatal(http.ListenAndServe(":8080", httpRouter))
}
```
The code creates two `GET` and one `POST` route to retrieve and create books. The first parameter is the path, that may contain path variables. Path variables start with a `:`. The second parameter is the handler function that handles the request. A handler function must be of the following type: `type HttpHandler func(http.ResponseWriter, *http.Request)`
The code creates two `GET` and one `POST` route to retrieve and create books. The first parameter is the path, that may contain path variables. Path variables use Go 1.22's standard syntax. The second parameter is the handler function that handles the request. A handler function must be of the following type: `type HttpHandler func(http.ResponseWriter, *http.Request)`
The first and second parameter are the `ResponseWriter` and the `Request` of Go's `http` package.

## Middleware
Expand Down Expand Up @@ -105,7 +105,7 @@ func main() {

httpRouter.Get("/books", getBooksHandler)
httpRouter.Post("/books", createBookHandler)
httpRouter.Get("/books/:bookId", getSingleBookHandler)
httpRouter.Get("/books/{bookId}", getSingleBookHandler)

httpRouter.FinishSetup()

Expand All @@ -131,7 +131,7 @@ func main() {

httpRouter.Get("/books", getBooksHandler)
httpRouter.Post("/books", createBookHandler)
httpRouter.Get("/books/:bookId", getSingleBookHandler)
httpRouter.Get("/books/{bookId}", getSingleBookHandler)

httpRouter.FinishSetup()

Expand Down Expand Up @@ -166,7 +166,7 @@ func main() {

httpRouter.Get("/books", getBooksHandler)
httpRouter.Post("/books", createBookHandler)
httpRouter.Get("/books/:bookId", getSingleBookHandler)
httpRouter.Get("/books/{bookId}", getSingleBookHandler)

httpRouter.FinishSetup()

Expand Down

0 comments on commit d81f719

Please sign in to comment.