Repository navigation
Convenience methods for form data and query string parsing #91
Replies: 1 comment
Design direction from ensemble explorationRan a full ensemble design process (3 design personas + 5 evaluation personas) and arrived at this direction after discussion. Key insight: thin wrappers aren't convenienceThe initial design had separate methods for each data source:
The first two don't earn their keep. Query params and urlencoded body parsing are already easy enough with the existing What would actually be convenientFrom the handler's perspective, a form submission is a form submission. Whether the client used GET with query params, POST with urlencoded body, or POST with multipart — the handler wants to look up field values and maybe grab file uploads. The transport mechanism is an HTTP implementation detail. A single unified API: match handler.params()
| let p: hobby.Params val =>
// text field — works regardless of encoding
match p.get("username")
| let name: String => // ...
end
// file upload — only present for multipart
match p.file("avatar")
| let file: hobby.FormFile val =>
// file.data(), file.filename(), file.content_type()
end
| let err: hobby.ParamsError =>
handler.respond(stallion.StatusBadRequest, err.string())
endOne method, one return type. Internally it dispatches on Content-Type:
The handler doesn't know or care which encoding was used. Settled decisions from the ensembleThese came out of the design + evaluation process and should carry forward:
Open questions for next iteration
|
Uh oh!
There was an error while loading. Please reload this page.
Hobby has no built-in convenience for parsing query strings, form-urlencoded POST bodies, or multipart form data. Users have to manually reach into the uri and multipart_mime libraries themselves.
Worth exploring adding convenience methods on Context for:
ParseFormURLEncoded/URI.query_params())application/x-www-form-urlencodedPOST body parsing (via uri'sParseFormURLEncoded)multipart/form-dataparsing (viamultipart_mime)The tradeoff: query string and form-urlencoded parsing would come for free since uri is already a transitive dependency. Multipart would add a new dependency on multipart_mime. Do we want hobby to take on that dependency, or leave multipart as something users pull in themselves?
All reactions