2013-05-16 15:21:13 +04:00
|
|
|
// # Ghost Data API
|
2014-06-03 17:05:25 +04:00
|
|
|
// Provides access from anywhere to the Ghost data layer.
|
|
|
|
//
|
|
|
|
// Ghost's JSON API is integral to the workings of Ghost, regardless of whether you want to access data internally,
|
|
|
|
// from a theme, an app, or from an external app, you'll use the Ghost JSON API to do so.
|
2013-05-16 15:21:13 +04:00
|
|
|
|
2014-06-20 13:15:01 +04:00
|
|
|
var _ = require('lodash'),
|
2014-08-17 10:17:23 +04:00
|
|
|
Promise = require('bluebird'),
|
2014-06-20 13:15:01 +04:00
|
|
|
config = require('../config'),
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 16:41:19 +04:00
|
|
|
// Include Endpoints
|
2014-08-21 01:42:34 +04:00
|
|
|
configuration = require('./configuration'),
|
2014-06-20 13:15:01 +04:00
|
|
|
db = require('./db'),
|
|
|
|
mail = require('./mail'),
|
|
|
|
notifications = require('./notifications'),
|
|
|
|
posts = require('./posts'),
|
2014-07-15 19:22:06 +04:00
|
|
|
roles = require('./roles'),
|
2014-06-20 13:15:01 +04:00
|
|
|
settings = require('./settings'),
|
|
|
|
tags = require('./tags'),
|
|
|
|
themes = require('./themes'),
|
|
|
|
users = require('./users'),
|
|
|
|
slugs = require('./slugs'),
|
|
|
|
authentication = require('./authentication'),
|
2014-07-15 14:40:14 +04:00
|
|
|
uploads = require('./upload'),
|
2014-07-19 16:20:16 +04:00
|
|
|
dataExport = require('../data/export'),
|
|
|
|
errors = require('../errors'),
|
2013-08-30 15:20:30 +04:00
|
|
|
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 16:41:19 +04:00
|
|
|
http,
|
|
|
|
formatHttpErrors,
|
2014-07-19 16:20:16 +04:00
|
|
|
addHeaders,
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 16:41:19 +04:00
|
|
|
cacheInvalidationHeader,
|
|
|
|
locationHeader,
|
|
|
|
contentDispositionHeader,
|
2014-05-06 02:38:05 +04:00
|
|
|
init;
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 16:41:19 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ### Init
|
|
|
|
* Initialise the API - populate the settings cache
|
|
|
|
* @return {Promise(Settings)} Resolves to Settings Collection
|
|
|
|
*/
|
|
|
|
init = function () {
|
|
|
|
return settings.updateSettingsCache();
|
|
|
|
};
|
2013-06-25 15:43:15 +04:00
|
|
|
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 16:41:19 +04:00
|
|
|
/**
|
|
|
|
* ### Cache Invalidation Header
|
|
|
|
* Calculate the header string for the X-Cache-Invalidate: header.
|
|
|
|
* The resulting string instructs any cache in front of the blog that request has occurred which invalidates any cached
|
|
|
|
* versions of the listed URIs.
|
|
|
|
*
|
|
|
|
* `/*` is used to mean the entire cache is invalid
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Express.request} req Original HTTP Request
|
|
|
|
* @param {Object} result API method result
|
|
|
|
* @return {Promise(String)} Resolves to header string
|
|
|
|
*/
|
|
|
|
cacheInvalidationHeader = function (req, result) {
|
2014-07-09 02:28:31 +04:00
|
|
|
var parsedUrl = req._parsedUrl.pathname.replace(/^\/|\/$/g, '').split('/'),
|
2013-09-24 19:21:43 +04:00
|
|
|
method = req.method,
|
2014-07-09 02:28:31 +04:00
|
|
|
endpoint = parsedUrl[0],
|
|
|
|
id = parsedUrl[1],
|
2013-11-03 21:13:19 +04:00
|
|
|
cacheInvalidate,
|
2014-04-22 05:04:30 +04:00
|
|
|
jsonResult = result.toJSON ? result.toJSON() : result,
|
|
|
|
post,
|
2014-06-04 02:38:15 +04:00
|
|
|
hasStatusChanged,
|
|
|
|
wasDeleted,
|
|
|
|
wasPublishedUpdated;
|
2013-11-03 21:13:19 +04:00
|
|
|
|
2013-09-24 19:21:43 +04:00
|
|
|
if (method === 'POST' || method === 'PUT' || method === 'DELETE') {
|
2013-12-25 04:05:20 +04:00
|
|
|
if (endpoint === 'settings' || endpoint === 'users' || endpoint === 'db') {
|
2014-03-26 16:45:54 +04:00
|
|
|
cacheInvalidate = '/*';
|
2013-09-24 19:21:43 +04:00
|
|
|
} else if (endpoint === 'posts') {
|
2014-04-22 05:04:30 +04:00
|
|
|
post = jsonResult.posts[0];
|
2014-06-04 02:38:15 +04:00
|
|
|
hasStatusChanged = post.statusChanged;
|
2014-04-22 05:04:30 +04:00
|
|
|
wasDeleted = method === 'DELETE';
|
2014-06-04 02:38:15 +04:00
|
|
|
// Invalidate cache when post was updated but not when post is draft
|
|
|
|
wasPublishedUpdated = method === 'PUT' && post.status === 'published';
|
2014-04-22 05:04:30 +04:00
|
|
|
|
|
|
|
// Remove the statusChanged value from the response
|
2014-06-04 02:38:15 +04:00
|
|
|
delete post.statusChanged;
|
2014-04-22 05:04:30 +04:00
|
|
|
|
|
|
|
// Don't set x-cache-invalidate header for drafts
|
2014-06-04 02:38:15 +04:00
|
|
|
if (hasStatusChanged || wasDeleted || wasPublishedUpdated) {
|
2014-10-28 03:41:18 +03:00
|
|
|
cacheInvalidate = '/, /page/*, /rss/, /rss/*, /tag/*, /author/*, /sitemap-*.xml';
|
2014-12-10 17:03:39 +03:00
|
|
|
if (id && post.slug && post.url) {
|
|
|
|
cacheInvalidate += ', ' + post.url;
|
2014-04-22 05:04:30 +04:00
|
|
|
}
|
2013-09-24 19:21:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-01-03 04:37:21 +04:00
|
|
|
|
2014-08-17 10:17:23 +04:00
|
|
|
return Promise.resolve(cacheInvalidate);
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 16:41:19 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ### Location Header
|
|
|
|
*
|
|
|
|
* If the API request results in the creation of a new object, construct a Location: header which points to the new
|
|
|
|
* resource.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Express.request} req Original HTTP Request
|
|
|
|
* @param {Object} result API method result
|
|
|
|
* @return {Promise(String)} Resolves to header string
|
|
|
|
*/
|
|
|
|
locationHeader = function (req, result) {
|
2014-05-02 03:42:23 +04:00
|
|
|
var apiRoot = config.urlFor('api'),
|
|
|
|
location,
|
2014-07-23 10:13:20 +04:00
|
|
|
newObject;
|
2014-05-02 03:42:23 +04:00
|
|
|
|
|
|
|
if (req.method === 'POST') {
|
|
|
|
if (result.hasOwnProperty('posts')) {
|
2014-07-23 10:13:20 +04:00
|
|
|
newObject = result.posts[0];
|
|
|
|
location = apiRoot + '/posts/' + newObject.id + '/?status=' + newObject.status;
|
|
|
|
} else if (result.hasOwnProperty('notifications')) {
|
|
|
|
newObject = result.notifications[0];
|
|
|
|
location = apiRoot + '/notifications/' + newObject.id;
|
|
|
|
} else if (result.hasOwnProperty('users')) {
|
|
|
|
newObject = result.users[0];
|
|
|
|
location = apiRoot + '/users/' + newObject.id;
|
2014-05-02 03:42:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-17 10:17:23 +04:00
|
|
|
return Promise.resolve(location);
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 16:41:19 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ### Content Disposition Header
|
|
|
|
* create a header that invokes the 'Save As' dialog in the browser when exporting the database to file. The 'filename'
|
|
|
|
* parameter is governed by [RFC6266](http://tools.ietf.org/html/rfc6266#section-4.3).
|
|
|
|
*
|
|
|
|
* For encoding whitespace and non-ISO-8859-1 characters, you MUST use the "filename*=" attribute, NOT "filename=".
|
|
|
|
* Ideally, both. Examples: http://tools.ietf.org/html/rfc6266#section-5
|
|
|
|
*
|
|
|
|
* We'll use ISO-8859-1 characters here to keep it simple.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @see http://tools.ietf.org/html/rfc598
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
contentDispositionHeader = function () {
|
2014-07-19 16:20:16 +04:00
|
|
|
return dataExport.fileName().then(function (filename) {
|
|
|
|
return 'Attachment; filename="' + filename + '"';
|
|
|
|
});
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 16:41:19 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ### Format HTTP Errors
|
|
|
|
* Converts the error response from the API into a format which can be returned over HTTP
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Array} error
|
|
|
|
* @return {{errors: Array, statusCode: number}}
|
|
|
|
*/
|
|
|
|
formatHttpErrors = function (error) {
|
|
|
|
var statusCode = 500,
|
|
|
|
errors = [];
|
|
|
|
|
|
|
|
if (!_.isArray(error)) {
|
|
|
|
error = [].concat(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
_.each(error, function (errorItem) {
|
|
|
|
var errorContent = {};
|
|
|
|
|
2014-09-10 08:06:24 +04:00
|
|
|
// TODO: add logic to set the correct status code
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 16:41:19 +04:00
|
|
|
statusCode = errorItem.code || 500;
|
|
|
|
|
|
|
|
errorContent.message = _.isString(errorItem) ? errorItem :
|
|
|
|
(_.isObject(errorItem) ? errorItem.message : 'Unknown API Error');
|
|
|
|
errorContent.type = errorItem.type || 'InternalServerError';
|
|
|
|
errors.push(errorContent);
|
|
|
|
});
|
|
|
|
|
|
|
|
return {errors: errors, statusCode: statusCode};
|
|
|
|
};
|
2014-05-07 09:28:51 +04:00
|
|
|
|
2014-07-19 16:20:16 +04:00
|
|
|
addHeaders = function (apiMethod, req, res, result) {
|
|
|
|
var ops = [],
|
|
|
|
cacheInvalidation,
|
|
|
|
location,
|
|
|
|
contentDisposition;
|
|
|
|
|
|
|
|
cacheInvalidation = cacheInvalidationHeader(req, result)
|
|
|
|
.then(function addCacheHeader(header) {
|
|
|
|
if (header) {
|
|
|
|
res.set({'X-Cache-Invalidate': header});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ops.push(cacheInvalidation);
|
|
|
|
|
|
|
|
if (req.method === 'POST') {
|
|
|
|
location = locationHeader(req, result)
|
|
|
|
.then(function addLocationHeader(header) {
|
|
|
|
if (header) {
|
2014-09-10 08:06:24 +04:00
|
|
|
res.set({Location: header});
|
2014-07-19 16:20:16 +04:00
|
|
|
// The location header indicates that a new object was created.
|
|
|
|
// In this case the status code should be 201 Created
|
|
|
|
res.status(201);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
ops.push(location);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (apiMethod === db.exportContent) {
|
|
|
|
contentDisposition = contentDispositionHeader()
|
|
|
|
.then(function addContentDispositionHeader(header) {
|
|
|
|
// Add Content-Disposition Header
|
|
|
|
if (apiMethod === db.exportContent) {
|
|
|
|
res.set({
|
|
|
|
'Content-Disposition': header
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
ops.push(contentDisposition);
|
|
|
|
}
|
|
|
|
|
2014-08-17 10:17:23 +04:00
|
|
|
return Promise.all(ops);
|
2014-07-19 16:20:16 +04:00
|
|
|
};
|
|
|
|
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 16:41:19 +04:00
|
|
|
/**
|
|
|
|
* ### HTTP
|
|
|
|
*
|
|
|
|
* Decorator for API functions which are called via an HTTP request. Takes the API method and wraps it so that it gets
|
|
|
|
* data from the request and returns a sensible JSON response.
|
|
|
|
*
|
|
|
|
* @public
|
|
|
|
* @param {Function} apiMethod API method to call
|
|
|
|
* @return {Function} middleware format function to be called by the route when a matching request is made
|
|
|
|
*/
|
|
|
|
http = function (apiMethod) {
|
2013-06-25 15:43:15 +04:00
|
|
|
return function (req, res) {
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 16:41:19 +04:00
|
|
|
// We define 2 properties for using as arguments in API calls:
|
|
|
|
var object = req.body,
|
2014-07-19 16:20:16 +04:00
|
|
|
response,
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 16:41:19 +04:00
|
|
|
options = _.extend({}, req.files, req.query, req.params, {
|
|
|
|
context: {
|
2014-06-30 16:58:10 +04:00
|
|
|
user: (req.user && req.user.id) ? req.user.id : null
|
2014-05-07 09:28:51 +04:00
|
|
|
}
|
2014-01-03 04:37:21 +04:00
|
|
|
});
|
2014-05-05 17:51:21 +04:00
|
|
|
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 16:41:19 +04:00
|
|
|
// If this is a GET, or a DELETE, req.body should be null, so we only have options (route and query params)
|
|
|
|
// If this is a PUT, POST, or PATCH, req.body is an object
|
|
|
|
if (_.isEmpty(object)) {
|
|
|
|
object = options;
|
|
|
|
options = {};
|
|
|
|
}
|
2014-05-07 09:28:51 +04:00
|
|
|
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 16:41:19 +04:00
|
|
|
return apiMethod(object, options)
|
|
|
|
// Handle adding headers
|
|
|
|
.then(function onSuccess(result) {
|
2014-07-19 16:20:16 +04:00
|
|
|
response = result;
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 16:41:19 +04:00
|
|
|
// Add X-Cache-Invalidate header
|
2014-07-19 16:20:16 +04:00
|
|
|
return addHeaders(apiMethod, req, res, result);
|
|
|
|
}).then(function () {
|
|
|
|
// #### Success
|
|
|
|
// Send a properly formatting HTTP response containing the data with correct headers
|
|
|
|
res.json(response || {});
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 16:41:19 +04:00
|
|
|
}).catch(function onError(error) {
|
2014-07-19 16:20:16 +04:00
|
|
|
errors.logError(error);
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 16:41:19 +04:00
|
|
|
// #### Error
|
|
|
|
var httpErrors = formatHttpErrors(error);
|
|
|
|
// Send a properly formatted HTTP response containing the errors
|
2014-08-09 17:48:58 +04:00
|
|
|
res.status(httpErrors.statusCode).json({errors: httpErrors.errors});
|
2014-05-05 17:51:21 +04:00
|
|
|
});
|
2013-06-08 09:05:40 +04:00
|
|
|
};
|
2013-06-25 15:43:15 +04:00
|
|
|
};
|
|
|
|
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 16:41:19 +04:00
|
|
|
/**
|
|
|
|
* ## Public API
|
|
|
|
*/
|
2013-12-06 12:51:35 +04:00
|
|
|
module.exports = {
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 16:41:19 +04:00
|
|
|
// Extras
|
|
|
|
init: init,
|
|
|
|
http: http,
|
|
|
|
// API Endpoints
|
2014-08-21 01:42:34 +04:00
|
|
|
configuration: configuration,
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 16:41:19 +04:00
|
|
|
db: db,
|
|
|
|
mail: mail,
|
|
|
|
notifications: notifications,
|
2013-12-06 12:51:35 +04:00
|
|
|
posts: posts,
|
2014-07-15 19:22:06 +04:00
|
|
|
roles: roles,
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 16:41:19 +04:00
|
|
|
settings: settings,
|
2013-12-06 12:51:35 +04:00
|
|
|
tags: tags,
|
2014-05-13 18:33:34 +04:00
|
|
|
themes: themes,
|
2014-05-06 02:38:05 +04:00
|
|
|
users: users,
|
2014-06-20 13:15:01 +04:00
|
|
|
slugs: slugs,
|
2014-07-15 14:40:14 +04:00
|
|
|
authentication: authentication,
|
|
|
|
uploads: uploads
|
2013-12-06 12:51:35 +04:00
|
|
|
};
|
2014-06-03 17:05:25 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ## API Methods
|
|
|
|
*
|
|
|
|
* Most API methods follow the BREAD pattern, although not all BREAD methods are available for all resources.
|
|
|
|
* Most API methods have a similar signature, they either take just `options`, or both `object` and `options`.
|
|
|
|
* For RESTful resources `object` is always a model object of the correct type in the form `name: [{object}]`
|
|
|
|
* `options` is an object with several named properties, the possibilities are listed for each method.
|
|
|
|
*
|
|
|
|
* Read / Edit / Destroy routes expect some sort of identifier (id / slug / key) for which object they are handling
|
|
|
|
*
|
|
|
|
* All API methods take a context object as one of the options:
|
|
|
|
*
|
|
|
|
* @typedef context
|
|
|
|
* Context provides information for determining permissions. Usually a user, but sometimes an app, or the internal flag
|
|
|
|
* @param {Number} user (optional)
|
|
|
|
* @param {String} app (optional)
|
|
|
|
* @param {Boolean} internal (optional)
|
|
|
|
*/
|