Official mRcore4 RESTful API Documentation! |
Why?I have created several RESTful API's simply because I wanted to learn how to develop webservices using PHP and REST. I sort of followed Twitters API URL style (http://dev.twitter.com/doc), if they can't do REST, no one can eh? Eventually I would like to create a native Android application for mRcore4 using these API's, and possibly experiment abstracting the database layer completely, making all queries through an API. It has already come in handy from a Linux command line. I created a bash script so I can simply type mr.topic 1 to get the plaintext version of topic ID 1, or mr.topic search linux to list all topics in plaintext that contain the word linux. Very handy since I'm in the command line 90% of the time. I can even append quick strings to an article with mr.topic append 1 'found a cool command line thingy here...'.:r: Authentication and PermissionsI use two types of authentication, Basic HTTP Authentication and Digest Authentication. Digest is the preferred method and if you are using a script as a webservice client (opposed to straight command line curl) I suggest you use the Digest parameters of curl. Basic HTTP Authentication is used if called from a command line (curl -u user:pass). The credentials and permissions used are the same as your regular website login account therefore you can only view and edit topics that you would normally have access too. Most of the API's can be accessed anonymously and do NOT require user authentication. To gain public access to an API you can either omit the user/pass or set the user/pass to anonymous. SyntaxIn the API documentation below, v stands for the API version number (versions are in the form of v1 v2 v3...), tid is a variable describing the topic ID, format is a variable describing the output format (options are xml or json). The output format can either be specified through the URL (rest/v/topic/255.json) or through the html Accept Header (curl -H "Accept: application/json"). The URL method is preferred and takes precedence over the Accept header and json is always the default output format if none is specified. |
The API is currently under construction, there will be lots more API functions soon, not that anyone cares since I'm the only one using it |
$jsonurl = 'http://mreschke.com/rest/v1/topic/255.json';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $jsonurl);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 10);
$json = curl_exec($ch);
curl_close($ch);
echo $json;