1.0.0 • Published 6 years ago

restful-fluency v1.0.0

Weekly downloads
4
License
ISC
Repository
github
Last release
6 years ago

restful-fluency

A fluent builder for creating REST and HTTP-based APIs.

Usage

Install the node package:

npm install --save restful-fluency

Import the server builder in your javascript code:

const ServerBuilder = require('./server-builder');

Server Types

Server TypeDescription
DEFAULTUses restify.
RESTIFYUses restify to serve requests.

Server Configuration Options

OptionDescription
whichListensOnPort(port)The port that the server will use to listen for incoming requests.
withARestfulApi()Add a new REST API
build()Builds the server with the current configuration.

REST API Configuration Options

OptionDescription
thatUsesMongoModel(model)The mongo (mongoose) model that will back this REST API.
accessibleFrom(resourcePrefix)The resource prefix to use.
withReadonlyAccess(hasReadAccessOnly)Set this to true if you want to disallow write operations.
and()Finalise the API and go back to configuring the server.

Example

ServerBuilder.DEFAULT
.withARestfulApi().thatUsesMongoModel(productModel).accessibleFrom('product').withReadonlyAccess().and()
.withARestfulApi().thatUsesMongoModel(orderModel).accessibleFrom('order').and()
.whichListensOnPort(8080)
.build();