shelf_helpers
library
Functions
allowedContentType <T extends Body > (List <ContentType > supportedContentType )
→ Middleware
allowedContentType check if the content-type in the request is part of
the supportedContentType
that your endpoint support
else return BadRequest
auth <T > (Auth <T > auth )
→ Middleware
auth middleware allow you to hook to get token, apiKey or something else
in order to check if credential are correct.
The function that check if credential are correct return
a record that look like this (bool, T) where T is defined by you.
authentication <T > ({FutureOr <(bool , T? ) > basicAuth (Request request , String authorization )?, FutureOr <(bool , T? ) > bearerAuth (Request request , String token )?, FutureOr <(bool , T? ) > apiKeyAuth (Request request , String value )?, FutureOr <(bool , T? ) > customAuth (Request request )?, String bearerPrefix = _bearer })
→ Middleware
bodyFieldAllowedValues <B extends Body > (String fieldName , List <String > allowedValues )
→ Middleware
bodyFieldAllowedValues check if the fieldName
value is allowed base on allowedValues
if check failed return BadRequest response
bodyFieldIsRequired <B extends Body > (String fieldName )
→ Middleware
bodyFieldIsRequired check if the fieldName
is present in the body
if check failed return BadRequest response
bodyFieldIsType <B extends Body , T > (String fieldName )
→ Middleware
bodyFieldIsType check if the fieldName
is type T
if check failed return BadRequest response
bodyFieldMaxLength <B extends Body > (String fieldName , int maxLength )
→ Middleware
bodyFieldMinLength check if the fieldName
length is under maxLength
if check failed return BadRequest response
bodyFieldMinLength <B extends Body > (String fieldName , int minLength )
→ Middleware
bodyFieldMinLength check if the fieldName
length is at least minLength
if check failed return BadRequest response
bodyFieldValidator <T extends Body > (String fieldName , bool validator (Object ? value ) )
→ Middleware
bodyFieldValidator run validator
on the field fieldName
if validator failed return BadRequest response
bodyValidator <T extends Body > (bool validator (Object ? value ) )
→ Middleware
bodyValidator is a flexible validator that allow you to check whatever
you need on the body
if validator failed return BadRequest response
cors ({String accessControlAllowOrigin = '*' , List <String > accessControlAllowMethod = const ['*'] , int accessControlMaxAge = 86400 })
→ Middleware
A Middleware
to add CORS
generateResponse (Request request , NetworkObject object , {int status = HttpStatus.ok , })
→ Response
Allow you to easily generate response based on accept header
object
is the object that will be serialized
you can specify the status code by changing status
defaultAcceptHeader
is used only if the request doesn't have accept header
getBody <T extends Body > (T deserializer (dynamic ), {required String objectName })
→ Middleware
getBody parse the body based on Content-Type automatically
parseBody <R extends Object , B extends Body > ()
→ Middleware
take a Body and parse it to put it in the context
you can then get it by using request.get<R>()
provide <T extends Object > (T create (Request request ) )
→ Middleware
Allow you to provide lazy value down
providePathParam <T extends Object > (T value )
→ Middleware
queryParameterValidator ({required bool required , required String name , required List <String > allowedValues })
→ Middleware
Use queryParameterValidator to verify if query parameter name
is allowed
you can provide the list of allowed value in allowedValues
if the query parameter is mandatory put required
at true and else at false
shelf_helpers 1.0.0-alpha.3