# restful **Repository Path**: mirrors_leecade/restful ## Basic Information - **Project Name**: restful - **Description**: reflect RESTful Director routers from Resourceful resources - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-08-09 - **Last Updated**: 2026-02-14 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Restful [](http://travis-ci.org/flatiron/restful) Reflects [RESTful](http://en.wikipedia.org/wiki/Representational_state_transfer) [Director](http://github.com/flatiron/director) routers from [resourceful](http://github.com/flatiron/resourceful) resources. Can be used as a stand-alone module or as a [Flatiron](http://github.com/flatiron/) plugin. # Explanation The restful project removes the process of writing boilerplate routing code for interacting with [resourceful](http://github.com/flatiron/resourceful) resources. Restful uses reflection to reflect an http router interface which maps all the restful routes needed to perform basic [CRUD](http://en.wikipedia.org/wiki/Create,_read,_update_and_delete) operations with [resourceful](http://github.com/flatiron/resourceful). restful also has the ability to expose additional arbitrary remote resource methods in it's http router interface. Through the removal of this boilerplate code, restful creates a robust, standardized, and re-usable http interface for any [resourceful](http://github.com/flatiron/resourceful) resource. **Remark:** If you don't like REST and would prefer a socket, use the [socketful](http://github.com/flatiron/socketful) library! # Installation npm install restful # Usage ## Define resource(s) ```js var resourceful = require('resourceful'), Creature = resourceful.define('creature'); Creature.property('type', String, { default: "dragon" }); Creature.property('life', Number, { default: 10, minimum: 0, maximum: 20 }); ``` *[additional API documentation for defining resources](http://github.com/flatiron/resourceful)* ## As a Flatiron plugin To use restful as a Flatiron plugin you will have to: - Define resource(s) in your Flatiron app - Use the restful plugin in your Flatiron app - Set `restful=true` on the resource to let Flatiron know to expose it Here is a code example of using restful as a Flatiron plugin: https://github.com/flatiron/restful/blob/master/examples/app.js ## As a stand-alone server To use restful as a stand-alone server you will have to: - Define resource(s) - Create a new server based on the resource(s) using `restful.createServer` Here is a code example of using restful as a stand-alone server: https://github.com/flatiron/restful/blob/master/examples/standalone-server.js ## As a middleware / custom router To use restful as a HTTP `req` `res` processing middleware you will have to: - Define resource(s) - Create a new router based on the resource(s) using `restful.createRouter` - Use the newly created router inside an existing HTTP server Here is a code example of using restful in a server: https://github.com/flatiron/restful/blob/master/examples/server.js ## Core HTTP REST Mappings By default, `restful` will map the following `Resourceful` methods. Verb Path Action Notes GET /creature => Creature.all() POST /creature => Creature.create() Create with no-id, id is auto-generated POST /creature/1 => Creature.create() Create with id "1" GET /creature/1 => Creature.show() PUT /creature/1 => Creature.update() DELETE /creature/1 => Creature.destroy() POST /creature/1/update => Creature.update() POST /creature/1/destroy => Creature.destroy() The `Director` router will dispatch all incoming RESTFul urls to the Creature resource and respond back with the appropriate result. ## Non-strict Mappings You'll notice that some of the routes defined above are not 100% restful ( such as `POST /creature/1/update` ). Since not all HTTP clients support PUT and DELETE Verbs ( such as forms in web browsers ), restful maps additional "non-strict" rest mappings to make your life slightly easier. If you prefer to not use this option, set `{ strict: true }`. *You might also want to consider using a rails-like approach which uses the convention of a reserved `