Falcor Wordpress Router
This project provides a Falcor Router which acts as a middleman (in node.js) for consuming the Wordpress REST API. The goal is a more intelligible, data-centric API for the client with dramatically reduced client network requests.
Getting Started
Basic installation and usage
npm install falcor-wordpress --save
Use it within an express app:
... // basic express boilerplate, app = express(); var FalcorServer = ;var wordpressRouter = ;var endpoint = 'http://demo.wp-api.org/wp-json/wp/v2'; app;
Included Demo
A demo running in express with a simple front-end is included.
# install library dependencies
npm install
# install demo dependencies and run
cd demo
npm install
npm start
# open your browser and visit http://localhost:9090
The demo page allows you to test live queries against the offical Wordpress Rest API demo site, including a number of examples to get you started. Watch the server console to see a list of REST endpoints that are being fetched on each flight.
Note: there are some differences betweeen the 1.0 and 2.0 branches of the WP API. This package targets 2.0, and uses a 2.0 endpoint for its demo.
Note 9-28-2015: the official Wordpress Rest API demo site has currently been taken offline; since its status is uncertain, the demo may require that you edit server.js
to point to your own instance of a Wordpress site running the REST API version 2. I'll update with further instructions to that end if it becomes clear that their public demo is permanently offline.
Currently implemented top-level routes
Below are the top-level routes available, along with some example paths that might be requested (try these live on the included demo).
postsById
Basic example: postsById[171,131]["title","slug","link"]
Going deeper: postsById[131].terms.category[0].name
recentPosts
Basic example: recentPosts[0..2].title
Going deeper: recentPosts[5].terms.category[0].name
postsByTerm[vocabulary][term-slug]
Example: postsByTerm.category.tool-kit[0..3]['title','id']
termsById[vocabulary]
Categories example: termsById.category[4,70]['name','description']
Tags example: termsById.tag[36]['slug','name']
taxonomies
Metadata: taxonomies.category.meta['name','slug']
Number of available terms: taxonomies.category.terms.length
Terms range: taxonomies.tag.terms[0..2]['name']
Other routes
These are also available at root, though generally more useful where referenced elsewhere:
authorsById
mediaById
Media linked as featured image: postsById[131].featured_image.media_details.sizes.thumbnail.file
Author of a post: postsById[171].author.name
Roadmap
- postsById
- recentPosts
- taxonomies (meta, terms list)
- termsById
- authorsById
- mediaById
- posts by term
- more linked subqueries
- additional listings by varied sorts