farrow-http
A Type-Friendly Web Framework
#
Table of Content- Table of Content
- API
#
API#
Http(options?: HttpPipelineOptions): HttpPipelinecreate a http server
#
Https(options?: HttpsPipelineOptions): HttpsPipelinecreate 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.
#
ResponseResponse
can be used to describe the shape of the real server response, farrow-http will perform it later
#
Router(): RouterPipelinecreate a router
#
Router-Url-SchemaSince 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 parameterA 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 parameterA 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' } }
router-url-schema
#
Current supported types in The supported types in <key:type>
are list below:
string
-> tsstring
number
-> tsnumber
boolean
-> tsboolean
id
-> tsstring
, butfarrow-schema
will ensure it's not emptyint
-> tsnumber
, butfarrow-schema
will ensure it's integerfloat
-> tsnumber
{*+}
-> use the string wrapped by{}
asstring literal type
. eg.{abc}
has type"abc"
, onlystring literal type
is supported|
-> tsunion types
. eg.<a:int|boolean|string>
has ts typenumber|boolean|string
#
Routing methodsrouter[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?)