REST API to manipulate form models and instances
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app
config
samples
test
.gitignore
.npmignore
.travis.yml
Procfile
README.md
package.json
server.js

README.md

form-server-api

Build Status Dependency Status

REST API to manipulate form models and instances. Node.js based form server used to store and retrieve JSON serialized HTML forms.

Usage

First be sure you have MongoDB and Node.js installed...

git clone https://github.com/linagora-open-paas/form-server-api.git
npm install
node server.js

Check config.js for configuration options.

Install

$ npm install

Run

Start the API server with nodemon to restart app on code change:

$ npm start

or start the API server in standard mode:

$ node server.js

Tests

$ npm test

API for Form Models

Base URI for forms is http://localhost:3000/forms

Method URL Description
GET /forms Returns a JSON array of forms.
GET /forms/:id Finds a form by ID and returns it as JSON.
GET /forms?name=:name Returns a JSON array of forms with the given name.
POST /forms Creates a form. Returns HTTP status 201 if created.
JSON body:
	<pre>
    {
      name : 'Form name',
      model : {}
    }
    </pre>
</td>
DELETE /forms/:id Deletes a form. Returns HTTP status 200 if an existing form with this id was deleted.
POST /forms/:id Updates an existing form.
JSON body:
    	{
      		name : 'Form name',
      		model : {}
    	}
		
	The body should only contain fields to modify.<br />
	Returns HTTP status 201 if updated.
</td>

API for Form Instances

Base URI for form instances is http://localhost:3000/instances

Method URL Description
GET /instances Returns a JSON array of form instances.
GET /instances/:id Finds a form instance by ID and returns it as JSON.
GET /instances?form_id=:form_id Returns a JSON array if instances associated with the form ID were found.
POST /instances Creates a form instance.
JSON body:
    	{
      		name : 'Form Instance name',
      		description : 'Instance Description',
      		form_id : 'the form model ID',
      		model : {}
    	}
		
	Returns HTTP status 201 if created.<br />
	Notice that a newly created instance is considered as "open".
</td>
DELETE /instances/:id Deletes a form instance. Returns HTTP status 200 if an existing instance with this ID was deleted.
POST /instances/:id Updates an existing instance.
JSON body:
    	{
      		name : 'Form Instance name',
      		description : 'Instance Description',
      		open : 'true or false',
      		model : {}
    	}
    	
	The body should only contain fields to modify.<br />  
	Although 'form_id' can be modified, it should not make sense.<br />  
	'open' indicates the status of an instance, i.e. if people can fill-in this form instance.

	<br /><br />
	Returns HTTP status 201 if updated.
</td>

API for Form Results

Note : Results are linked to instances.

Base URI for form instances is http://localhost:3000/results

Method URL Description
GET /results Returns a JSON array of form results.
GET /results/:id Finds a form result by ID and returns it as JSON.
GET /results?instance=:instance_id Returns a JSON array if results for the given form instance.
POST /results Creates a form result.
JSON body:
    	{
      		instance : 'the instance model ID',
      		paramA : 'valueA',
      		paramB : 'valueB'
    	}
		
	Returns HTTP status 201 if created.<br />
</td>
DELETE /results/:id Deletes a form result. Returns HTTP status 200 if an existing result with this ID was deleted.
POST /results/:id Updates an existing result.
JSON body:
    	{
    	    paramC : 'valueC'
    	}
    	
	The body should only contain fields to modify or to add.<br />
	Although 'instance_id' can be modified, it should not make sense.<br />
	<br /><br />
	Returns HTTP status 201 if updated.
</td>

Samples

Create a new form

node samples/post.js

Delete a form

node samples/delete.js

Prompts for the id of the form you want to delete and then performs the request.