- Currently Software Architect @ ShopUp We’re a JavaScript shop and we are hiring - Writing JavaScript professionally for 9 years - Developer of Avro Keyboard - Dad of a wonderful kid Twitter: @MehdiHK GitHub: https://github.com/mugli LinkedIn: https://www.linkedin.com/in/mehdihk/
or snake _case? • Version in the url or header or param? • Verbs are bad? How do I make search endpoints? • Should GET requests have body? • Do you even paginate bro? Cursor or offset? • Formatted output or minified? • How do I avoid over-fetching?
error message • Consistent error object • Declarative syntax, no ugly regex hacks, type checks • What’s expected is immediately visible • Makes refactoring easy for other API developers • Can be used to check response object too before they are send to the client! (Not shown in the example)
for REST APIs, which allows both humans and computers to discover and understand the capabilities of a service without requiring access to source code, additional documentation, or inspection of network traffic.
least specific. • If you have two routes, /filename.jpg and /filename.{ext} a request to /filename.jpg will match the first route, and not the second, whatever their order is in code. • That also mean, a route with the path /{files*} will be the last route tested, and will only match if all other routes fail.
to one route, and its routing table will be the same every time you start the server. • As the application size and teams grow, routing conflicts become more of a concern. You want a banana but you get a gorilla holding the banana and the entire jungle. • If you have two routes that conflict, hapi will show an error on startup, providing details on the routes that conflict, making it much easier to debug and fix. This is much better than spending hours debugging this at runtime.
to spawn the whole server • You don’t need to listen to a socket • You don’t even need to send a real http call and process it • Because you are not testing if the underlying http stack is working in Node.js, you are testing if you pass some values to your endpoint, if it returns correct result
learning and prototyping. Unfortunately it became the most popular framework in Node.js ecosystem for the same reason. There are better options though. • Hapi brought a lot of battle tested and production ready practices to Node.js • Fastify had the luxury of coming later and learnt from both of them. • If you are stuck with existing express based api, there are middlewares that tries to make it better.