This package has been deprecated

Author message:

## NO LONGER MAINTAINED

apeman-app-rest

6.0.14 • Public • Published

apeman-app-rest

Build Status Code Climate Code Coverage npm Version JS Standard

apeman app to handle restful endpoint.

Installation

$ npm install apeman-app-rest --save

Usage

  1. Define an app within Apemanfile.js
  2. Call the app via apeman app command.

Apemanfile.js

/** This is an example Apemanfile to use apeman-app-rest */
 
'use strict'
 
const db = require('./db') // Apeman db modle instance
const { User } = db.models
 
module.exports = {
  $pkg: { /* ... */ },
  $apps: {
    // Define your own app.
    'my-app-01': {
      // Map url and handlers.
      '/': [
        require('apeman-app-rest')(User, {
          // Options
        })
      ]
    }
  }
}
 

Then,

$ apeman app my-app-01 -p 3000
'use strict'
 
const apemanrequest = require('apemanrequest')
const co = require('co')
const assert = require('assert')
 
let request = apemanrequest.create({ jar: true })
 
co(function * () {
  // Create a resource.
  {
    let res = yield request({
      method: 'POST',
      url: 'http://localhost:3000/user',
      form: {
        account_name: 'foo_bar',
        email: 'apbc@example.com'
      }
    })
    /* ... */
  }
 
  // Get a resource.
  {
    let res = yield request({
      method: 'GET',
      url: 'http://localhost:3000/user/1' // Pass resource id as url-param.
    })
    /* ... */
  }
 
  // List resource.
  {
    let res = yield request({
      method: 'GET',
      url: 'http://localhost:3000/user?account_name.$like=foo&limit=5&offset=5'
    })
    /* ... */
  }
 
  // Update the resource.
  {
    let res = yield request({
      method: 'PATCH',
      url: 'http://localhost:3000/user/1', // Pass resource id as url-param.
      form: {
        account_name: 'foo_bar2_updated'
      }
    })
    /* ... */
  }
 
  // Destroy the resource.
  {
    let res = yield request({
      method: 'DELETE',
      url: 'http://localhost:3000/user/1' // Pass resource id as url-param.
    })
    /* ... */
  }
}).catch((err) => {
  console.error(err)
})
 

Signature

apemanAppRest(models, options) -> function

apeman app to handle restful endpoint.

Args
Name Type Default Description
models object Model objects.
options object Optional settings.
options.pathname function '/'+apemanmodel.toType(model) Spec path name.
options.knock Endpoint boolean
options.spec Endpoint boolean
options.list Endpoint boolean
options.create Endpoint boolean
options.bulkUpdate Endpoint boolean
options.bulkDestroy Endpoint boolean
options.one Endpoint boolean
options.update Endpoint boolean
options.destroy Endpoint boolean
options.relatedList Endpoint boolean
options.relatedCreate Endpoint boolean
options.relatedUpdateBulk Endpoint boolean
options.relatedDestroyBulk Endpoint boolean
options.relatedOne Endpoint boolean
options.relatedUpdate Endpoint boolean
options.relatedDestroy Endpoint boolean
options.relationList Endpoint boolean
options.relationCreate Endpoint boolean
options.relationUpdate Endpoint boolean
options.relationDestroy Endpoint boolean

License

This software is released under the MIT License.

Links

Readme

Keywords

Package Sidebar

Install

npm i apeman-app-rest

Weekly Downloads

58

Version

6.0.14

License

MIT

Last publish

Collaborators

  • okunishinishi