https://github.com/hash-bang/express-restify-mongoose-queryizer
Middleware for express-restify-mongoose which allows direct querying via GET without JSON structures
https://github.com/hash-bang/express-restify-mongoose-queryizer
Last synced: 3 months ago
JSON representation
Middleware for express-restify-mongoose which allows direct querying via GET without JSON structures
- Host: GitHub
- URL: https://github.com/hash-bang/express-restify-mongoose-queryizer
- Owner: hash-bang
- License: mit
- Created: 2016-02-12T00:47:07.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-02-18T06:22:02.000Z (over 9 years ago)
- Last Synced: 2025-02-02T04:32:13.168Z (4 months ago)
- Language: JavaScript
- Size: 7.81 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
express-restify-mongoose-queryizer
==================================
Middleware for [express-restify-mongoose](https://florianholzapfel.github.io/express-restify-mongoose) which allows direct querying via GET without JSON structures.The 2.0.0 release of ERM moved GET based querying into the `query` structure like this:
http://myserver.com/api/widgets?query={"type":"foobar"}&sort=title
This middleware layer allows the old-style method of filtering directly within the GET request:
http://myserver.com/api/widgets?type=foobar&sort=title
Meta fields and the existing `query` structure is still maintained allowing for compatibility with regular ERM query syntax.
Installation
------------
Install via NPM:npm --save install express-restify-mongoose-queryizer
Then somewhere in your express application install it as middleware:
app.use(require('express-restify-mongoose-queryizer')({
// Whether to rewrite queries (see above examples)
rewriteQuery: true,// If we do rewrite should we also remove the key from req.query (not recommended if you have other middleware that relies on req.query)
rewriteQueryDeleteKeys: false,// Only rewrite query strings during GET operation
rewriteGetOnly: true,// Allow JSON objects as values
rewriteParseJSON: true,// Also use the HSON parser (allows non-quoted strings) instead of the plain JSON.parse()
rewriteParseHSON: true,// Rewrite 'POST' operations to 'PATCH'
postToPatch: true,// ... but only if they match this URL format - e.g. /api/widgets/56c528046ce4b00f517eb55c
postToPatchUrl: /^\/api\/.+\/[0-9a-f]{24}$/,
}));