Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/martindale/provide
Express middleware to "provide" resources.
https://github.com/martindale/provide
Last synced: 10 days ago
JSON representation
Express middleware to "provide" resources.
- Host: GitHub
- URL: https://github.com/martindale/provide
- Owner: martindale
- Created: 2014-06-24T23:27:04.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-07-16T03:52:12.000Z (over 10 years ago)
- Last Synced: 2024-10-06T03:08:17.503Z (about 1 month ago)
- Language: JavaScript
- Size: 172 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
provide
=======Express middleware to "provide" resources as both JSON objects and rendered HTML documents.
provides assumes you have a template configured by the same name as the provided object.
## Example
```javascript
var app = require('express')();/* configure view engine, using Jade (defaults to ./views/) */
app.set('view engine', 'jade');/* enable the use of res.provide */
app.use( require('provide') );/* an example route */
app.get('/thing', function(req, res, next) {
res.provide('thing', {
thing: { foo: 'bar' }
});
});app.listen(3000);
```
### Results
```
> curl -H "Accept: application/json" http://localhost:3000/thing
{"foo": "bar"}
```
Requesting an HTML version of that "thing" will give you exactly that:
```
> curl -H "Accept: text/html" http://localhost:3000/thing...
```