REST API
MongoDB uses feathersjs for it's server. It's a lightweight framework that sits onto of express and makes organizing a complex server more simple.
Meanbase currently has 16 endpoint suites.
- ban - Banned commentors
- comments - Interacting with comments
- custom - An endpoint designed for themes and extensions to use if they can't find another endpoint
- extension-uploads - Uploads an extension
- extensions - Contains records up loaded extensions
- image-uploads - Uploads an image
- images - Contains uploaded images
- menus - Interacts with site menus
- pages - Interacts with site pages
- roles - Roles and permission for users
- settings - Contains things like, recaptcha code, analytics code, or other settings for the site
- staging - Contains autosave data for everything
- theme-uploads - Uploads a new theme
- themes Contains uploaded themes
- user - Manage users
- wordpress-import - Import data from WordPress
To use any of them inject api
into your angular service, controller, or directive and call
api.serviceNameHere.find(queryObject)
Just replace serviceNameHere
with the api you are hitting.
You can also inject toastr and use it to show messages to the user.
Since es8 is running this code should work. Just make sure babel compiles it into es5 when you deploy your extension or theme.
async function fetchHomePage() {
try {
let pages = await api.pages.find({url: '/'})
let page = pages[0]
if(page) {
toastr.success('Found the home page.')
}
} catch(err) {
toastr.warning('Could not find the homepage.')
}
}
You have these available methods
- api.pages.create(content)
- returns array or object of item(s) created
- api.pages.find(identifier)
- returns array of data
- api.pages.update(identifier, replacementContent)
- returns array or object of item(s) updated
- api.pages.upsert(identifier, replacementContent)
- returns array or object of item(s) updated
- api.pages.delete(identifier)
- returns item/items deleted
- api.pages.findOne(id)
- returns found object
- api.pages.updateOne(id, replacementContent)
- return object of item updated
- api.pages.deleteOne(id)
- returns item deleted
Pagination
If the api supports pagination then results will come as
{
"total": 1,
"limit": 30,
"skip": 0,
"data": [{
"email": "[email protected]",
"content": "It works",
"url": "/why-cms",
"updatedAt": "2016-09-03T22:03:06.566Z",
"createdAt": "2016-09-03T22:03:06.566Z",
"approved": true,
"date": "2016-09-03T22:03:06.566Z",
"author": "codingfriend",
"__v": 0
}]
}
The actual content will be on the data
property. Currently, only the comments api is paginated
API Schemas
Custom
{
belongsTo: "extension or theme label",
key: "The id for this content",
enabled: "Boolean - whether only authorized users should see this",
value: "Anything",
permission: "The permission users need to see unenabled content"
}
Pages
{
url: '/example',
editability: 'roleName',
visibility: 'roleName',
template: 'article',
author: "Person's name",
tabTitle: 'How the page appears in the browser tab',
title: 'Title for the page',
description: 'Google description of the page',
summary: 'Like description',
created: Date.now(),
content: [{
location: "Location identifier of text",
text: "Html text for content
}],
images: [{
url: "Url to image",
alt: "Alternate text for screenreaders",
attribute: "Author of image",
location: "Location identifier on page for image"
}],
lists: "Any",
published: "Boolean",
likes: "Number of likes"
}
Note on pages: Content and images are dynamically altered before they reach the server and before they leave the server. Content enters in this format
{
body1: "My page content in the body",
footer1: "My footer text",
anythingYouWant: "My arbitrary text."
}
This gets converted to the array format seen above. The same is true of images.
Menus
{
title: 'text for the menu',
url: 'url this menu belongs to',
linkTo: "page._id",
location: 'which menu set the menu is in',
position: 'the order number of that menu in that menu set',
classes: 'menu classes',
target: 'html target attribute',
published: false
}
Comment
{
author: "Comment author name",
content: "Comment text",
url: "Which page url this comment belongs to",
date: "Timestamp comment was made",
email: "Author email",
ip: "IP Address of author",
gravatar: "Image url",
approved: "Boolean for if comment is approved",
likes: "Number of likes",
meta: "Any other information"
}
Images
{
url: "Url to image",
alt: "Alternate description for screenreaders",
attribute: "Image owner",
groups: ["Which groups does the image belong to"],
galleries: ["Which galleries is the image used in"]
}
Role
{
role: "Role name",
permissions: {
editContent: "true or false",
publishContent: "true or false",
deleteContent: "true or false",
manageMedia: "true or false",
manageExtensions: "true or false",
moderateComments: "true or false",
manageUsers: "true or false",
manageRoles: "true or false",
changeSiteSettings: "true or false",
importExportData: "true or false",
allPrivilages: "true or false",
}
}
User
{
name: "User's Name",
email: "User's Email",
role: "User role name",
enabled: "Whether the account is usable or not",
password: "Password Hash",
}
Settings
{
name: "Setting name",
value: "Mixed type, any value"
}
Extensions
{
label: "Extension Name",
folder: "Name of extension folder",
screenshot: "Url to extension screenshot",
html: "url of html page",
contents: "the extension.min.js file url",
active: "Boolean about whether the extension is usable"
}
Themes
{
author: "Theme author name",
email: "Theme author email",
website: "Theme website",
title: "Theme name",
description: "Description of theme.",
url: "Theme folder name",
preview: "Url to screenshot of theme",
active: "Boolean if theme is currently being used",
templates: {
"theme-template": ["page-type", "page-type"],
"theme-template-2": ["page-type"],
},
templatePaths: [
"template-name": "Url to template html file"
],
scriptsPath: "Path to scripts.html",
stylesPath: "Path to styles.html",
themeJSONPath: "Path to theme.json",
meta: "Mixed type - any additional information"
}