4 ms·
Is this a new wiki page? I've seen bits and pieces here and there in the net/http docs but nothing nearly as extensive. I think the stdlib is awesome, but the
by bacongobbler 10y ago
Is this a new wiki page? I've seen bits and pieces here and there in the net/http docs but nothing nearly as extensive.
I think the stdlib is awesome, but the biggest gripe I have with the standard net/http library would be the multiplexer (ServeMux). Out of the box if you provide it with a handle like /foo but the user making a request adds a trailing slash (e.g. GET /foo/), it returns a 404, compared to other libraries like julienschmidt/httprouter which will handle cases like this for you.
For example: https://play.golang.org/p/Q96EulBUfI https://play.golang.org/p/Q96EulBUfI
Other than that I think the stdlib is bang-on for simple http servers. Wouldn't recommend it if you're planning on writing a web server backed by a database, however. Compared to other web frameworks like django, the stdlib is a great library for working at a lower level in the stack, whereas Django is more of a content-oriented framework built around higher level concepts like basic CRUD applications.
- zemo 10y agoit's been around since before Go 1.0
- chrisper 10y agoNo, it has been around forever. It was the first page I used to see how to make a web app in Go.
- lobster_johnson 10y agoThe first thing people tend to do is to replace the default, very primitive "mux" with a router that more closely aligns with modern expectations, such as httprouter (https://github.com/julienschmidt/httprouter https://github.com/julienschmidt/httprouter) or chi (https://github.com/pressly/chi https://github.com/pressly/chi). These libraries also support middleware wrapping [1], a technique that the default mux supports but doesn't help you with. For example, adding CORS headers or logging the request. [1] https://justinas.org/writing-http-middleware-in-go/ https://justinas.org/writing-http-middleware-in-go/
- eternalban 10y agoI think Go is being strictly correct here: https://play.golang.org/p/eSDl2MuFdP https://play.golang.org/p/eSDl2MuFdP
- codebeaker 10y agoIsn't being "technically" correct, but actually not doing what people expect kinda frowned upon? > Be conservative in what you do, be liberal in what you accept from others [1]: https://en.wikipedia.org/wiki/Robustness_principle https://en.wikipedia.org/wiki/Robustness_principle
- jasonkostempski 10y agoI despise that quote. Regardless of what the intended message was, what it implies is a horrible recipe for life-long support of shitty client behavior.