6 ms·
A perfect API would consist of a few parts: 1. A request type and an associated response type 2. Impls for converting an HTTP request into the request type, a
by Kinrany 4y ago
A perfect API would consist of a few parts:
1. A request type and an associated response type
2. Impls for converting an HTTP request into the request type, and the reverse for response
3. A server type with an impl for handling the request
4. A client type with an impl for sending the request
The remaining challenge is making all this ergonomic for the simple cases.
- xena 4y agoFun fact: you just described Go's net/http package.
- metadaemon 4y agoIt's also pretty much Express.js
- zemo 4y agonot really, point 2 isn't in the standard library.
- xena 4y agohttps://pkg.go.dev/net/http?utm_source=godoc#ReadRequest https://pkg.go.dev/net/http?utm_source=godoc#ReadRequest
- zemo 4y agothat’s not what the Axum example does. The function you’re linking turns an opaque run of bytes into an http request object. What the Axum example does is turn an http request object into a value of some other type T.
- masklinn 4y agoThat's essentially what happens in Rust, but it's a layer of crates.
- zemo 4y ago1, 3, and 4 are already there, they're just a part of Hyper, not Axum/Warp/Rocket. 2 is basically the thing that Axum/Warp/Rocket provide. Hyper is kinda like net/http and Axum/Warp/Rocket are more feature rich. The thing is, they're super early. They don't remind me of the pared-down quality simplicity of the Gorilla Toolkit or even the feature paradise of Gin. Honestly it a lot of the Rust http frameworks strike me as eerily similar to either Falcore or Revel. Falcore was a very early Go http application framework built by ngmoco, a now-defunct game company. Falcore didn't really gain a lot of traction, partially because it provided abstractions that weren't very ergonomic. It's whole thing was that the core abstraction was a modular pipeline. https://github.com/ngmoco/falcore https://github.com/ngmoco/falcore I think most people know Revel, it's a little less obscure. It's philosophically the precursor to Gin.
- Kinrany 4y agoThe frameworks provide 2 by hiding 1. This makes it impossible to use the request and response types for other purposes.
- dman-os 4y agoThe examples showcased by Axum and co. are the "ergonomic simple cases" and it's easy to morph what's provided into any flavor you personally prefer with as many `impl`s and types. Here's[0] my jam rn. [0]: https://github.com/dman-os/template_rust_web_api/blob/main/src/user/create.rs https://github.com/dman-os/template_rust_web_api/blob/main/s...