1.1.1 • Published 8 years ago

yo-generic-api v1.1.1

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

Generic api

(Rough sketch v1)

Note: All logic is blocking, i.e validation is blocking, can be changed to async pattern too!

Important files:

config.js contains example config for a resource.

	module.exports = {
		PAGE_SIZE: 10,
		DEMO_CONFIG: {
			model: 'User',
			enableModifiers: true,
			modifierRules: { slug: ['slugify', 'uppercase'] },
			methods: ['get', 'post', 'put'],
			path: '/user',
			paramsArray: ['id', 'email', 'name'],
			paramsRulesList: {
				name: {
					rules: [{ name: 'length', max: 3, min: 2 }]
				},
				email: {
					rules: [{ name: 'email' }]
				}
			}
	}
}```

You can create new instance of generic-api for different resources. A resource in this context refers to an entity like User, Car, Product etc.

# Steps to use

require('yo-generic-api')
const Resource = require('yo-generic-api').Resource
const user = new Resource()
user.init(app, config)

## Note: app parameter should have mongoose model attached for database calls to work. Eg: app.db.models.User

Current working routes:

get: Fetch Items (use queryStrings for searching)
post: Create an item
put: Update items (use queryStrings for creating filters)
delete: Delete items (Use ?operator=in&by=id for deleting multiple items by _id, also pass array of id:['1st id','2nd id'] as body)
1.1.1

8 years ago

1.1.0

8 years ago

1.0.9

8 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago