farrow-http
A Type-Friendly Web Framework
Table of Content#
- Table of Content
- API
API#
Http(options?: HttpPipelineOptions): HttpPipeline#
create a http server
Https(options?: HttpsPipelineOptions): HttpsPipeline#
create a https server
- tls HttpsOptions Intersection between options from tls.createServer() and tls.createSecureContext() in Node.js
Notes: Server created by http is different from created by https.
Response#
Response can be used to describe the shape of the real server response, farrow-http will perform it later
Router(): RouterPipeline#
create a router
Router-Url-Schema#
Since farrow v1.2.0, a new feature router-url-schema is supported. it combines { pathname, params, query } into { url }, and use Template literal types to extract the type info
Dynamic parameter#
A dynamic parameter has the form <key:type>.
- if it was placed in
pathname(before?in a url), it will regard asparams[key] = type. the order is matter - if it was placed in
querystring(after?in a url), it will regard asquery[key] = type. the order is't matter
Dynamic parameter support modifier(learn more from here), has the form:
<key?:type>means optional, the corresponding type is{ key?: type }, the corresponding pattern is/:key?<key*:type>means zero or more, the corresponding type is{ key?: type[] }, the corresponding pattern is/:key*<key+:type>means one or more, the corresponding type is{ key: type[] }, the corresponding pattern is/:key+
Static parameter#
A static parameter can only be placed in querystring, it will regard as literal string type.
For example: /?<a:int>&b=2 has the type { pathname: string, query: { a: number, b: '2' } }
Current supported types in router-url-schema#
The supported types in <key:type> are list below:
string-> tsstringnumber-> tsnumberboolean-> tsbooleanid-> tsstring, butfarrow-schemawill ensure it's not emptyint-> tsnumber, butfarrow-schemawill ensure it's integerfloat-> tsnumber{*+}-> use the string wrapped by{}asstring literal type. eg.{abc}has type"abc", onlystring literal typeis supported|-> tsunion types. eg.<a:int|boolean|string>has ts typenumber|boolean|string
Routing methods#
router[get|post|put|patch|head|delte|options](url, schema?, options?) is supported as shortcut of router.match({ url, method: get|post|put|patch|head|delte|options }, options?)