This plugin is currently designed to generate a Read-only OData API interface for any Wordpress powered website.
The plugin tries to:
- Follow OData terminology for its parameters.
- Follow a pseudo MVC pattern and routing for endpoints
- Allow an easy way to override default templates included with the plugin should the Protocol change or require customizations
- Allows Wordpress methods and functions used in "The Loop" to be used.
- Mod_Rewite is enabled (Pretty Standard Really...).
- Permalinks are set to anything but the default setting. The plugin reqiures hitting the URI of
/OData/OData.svc
at a minimum so the default won't work unless your links are pointing toindex.php?odata=OData.svc
.
http://<blogurl>/OData/OData.svc/ => index.php?odata=OData.svc
http://<blogurl>/OData/OData.svc/<entitySet>/ => index.php?odata=OData.svc&entitySet=<entitySet>
http://<blogurl>/OData/OData.svc/<entitySet>(<entityID>)/ => index.php?odata=OData.svc&entitySet=<entitySet>&entityID=<entityID>
NOTE:
<entitySets>
SHOULD take their plural forms. Meaning the default Wordpress post_type
is post
BUT the <entitySet>
should be written as Posts
or posts
NOT Post
or post
. Same goes for post_type
of Page
.
Why?
It's to follow the idea of collections or entitySets
as they represent multiple entries
.
You can think of templates here as the view layer in an MVC-ish way. The controllers will generate the appropriate query_posts()
with $args
. It hasn't been implemented yet but the templates will in the future reflect the Methods name. Therefore if the Entities Controller (\controllers\entities_controller.php
) has a method show()
(which it does), it should have a corresponding template/view file named show.php
in the \templates\entities\
folder.
The templates (Views) that generate the OData payload by default are found in the templates directory. Within this directory there are currently 3 subfolders:
- defaults (Generates Error Views)
- entities (Generates Entity Views i.e. an Indivdual Post)
- entitysets (Generates Entity Set Views i.e. a Post Type, Page Type or Custom Post Type)
You can override the default templates included with the plugin by createing your own within a Wordpress theme. Just add the following folders and files:
- odata
- tempaltes
- defaults
odata.svc.php
(replaceshttp://<blogurl>/OData/OData.svc/
)odata_error_no_data_found.php
(replaces the default error page)
- entitysets
show.php
(replaceshttp://<blogurl>/OData/OData.svc/<entitySet>/
)
- entities
show.php
(replaceshttp://<blogurl>/OData/OData.svc/<entitySet>(entityID)/
)
- defaults
- tempaltes