Skip to content

Commit

Permalink
improved the examples documentation, corrected the stack overflow sup…
Browse files Browse the repository at this point in the history
…port url in the live examples
  • Loading branch information
Arul- committed Oct 30, 2011
1 parent c4717ca commit f8fac79
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 46 deletions.
2 changes: 1 addition & 1 deletion examples/_001_helloworld/readme.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<li><a title="Restler Home" href="http://luracast.com/products/restler/">Home</a></li>
<!--<li><a title="Using Restler" href="#">Guide</a></li><li><a title="Restler API Reference" href="#">API</a></li>-->
<li><a class="active" href="../index.html">Examples</a></li>
<li><a title="Share your knowledge by answering user questions in Stack Overflow." href="http://bit.ly/RestlerSupport">Support</a></li>
<li><a title="Share your knowledge by answering user questions in Stack Overflow." href="http://bit.ly/Restler-QA">Support</a></li>
<li><a title="Contribute and Fork Restler on GitHub" href="http://bit.ly/LuracastRestler">GitHub</a></li>
<li><a title="Get updated on Twitter" href="http://twitter.com/Luracast">Twitter</a></li>
</ul>
Expand Down
Empty file modified examples/_001_helloworld/readme.md
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion examples/_002_minimal/readme.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<li><a title="Restler Home" href="http://luracast.com/products/restler/">Home</a></li>
<!--<li><a title="Using Restler" href="#">Guide</a></li><li><a title="Restler API Reference" href="#">API</a></li>-->
<li><a class="active" href="../index.html">Examples</a></li>
<li><a title="Share your knowledge by answering user questions in Stack Overflow." href="http://bit.ly/RestlerSupport">Support</a></li>
<li><a title="Share your knowledge by answering user questions in Stack Overflow." href="http://bit.ly/Restler-QA">Support</a></li>
<li><a title="Contribute and Fork Restler on GitHub" href="http://bit.ly/LuracastRestler">GitHub</a></li>
<li><a title="Get updated on Twitter" href="http://twitter.com/Luracast">Twitter</a></li>
</ul>
Expand Down
Empty file modified examples/_002_minimal/readme.md
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion examples/_003_multiformat/readme.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<li><a title="Restler Home" href="http://luracast.com/products/restler/">Home</a></li>
<!--<li><a title="Using Restler" href="#">Guide</a></li><li><a title="Restler API Reference" href="#">API</a></li>-->
<li><a class="active" href="../index.html">Examples</a></li>
<li><a title="Share your knowledge by answering user questions in Stack Overflow." href="http://bit.ly/RestlerSupport">Support</a></li>
<li><a title="Share your knowledge by answering user questions in Stack Overflow." href="http://bit.ly/Restler-QA">Support</a></li>
<li><a title="Contribute and Fork Restler on GitHub" href="http://bit.ly/LuracastRestler">GitHub</a></li>
<li><a title="Get updated on Twitter" href="http://twitter.com/Luracast">Twitter</a></li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion examples/_004_error_response/readme.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<li><a title="Restler Home" href="http://luracast.com/products/restler/">Home</a></li>
<!--<li><a title="Using Restler" href="#">Guide</a></li><li><a title="Restler API Reference" href="#">API</a></li>-->
<li><a class="active" href="../index.html">Examples</a></li>
<li><a title="Share your knowledge by answering user questions in Stack Overflow." href="http://bit.ly/RestlerSupport">Support</a></li>
<li><a title="Share your knowledge by answering user questions in Stack Overflow." href="http://bit.ly/Restler-QA">Support</a></li>
<li><a title="Contribute and Fork Restler on GitHub" href="http://bit.ly/LuracastRestler">GitHub</a></li>
<li><a title="Get updated on Twitter" href="http://twitter.com/Luracast">Twitter</a></li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion examples/_005_protected_api/readme.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<li><a title="Restler Home" href="http://luracast.com/products/restler/">Home</a></li>
<!--<li><a title="Using Restler" href="#">Guide</a></li><li><a title="Restler API Reference" href="#">API</a></li>-->
<li><a class="active" href="../index.html">Examples</a></li>
<li><a title="Share your knowledge by answering user questions in Stack Overflow." href="http://bit.ly/RestlerSupport">Support</a></li>
<li><a title="Share your knowledge by answering user questions in Stack Overflow." href="http://bit.ly/Restler-QA">Support</a></li>
<li><a title="Contribute and Fork Restler on GitHub" href="http://bit.ly/LuracastRestler">GitHub</a></li>
<li><a title="Get updated on Twitter" href="http://twitter.com/Luracast">Twitter</a></li>
</ul>
Expand Down
44 changes: 40 additions & 4 deletions examples/_006_crud/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,48 @@
Tagline: using POST, GET, PUT and DELETE.
Description: Create, Retrive, Update and Delete using
HTTP methods POST, GET, PUT and DELETE respectively.
For simplicity and making it work out of the box it is using
**How the automatic routing is done?**
Restler uses *get, put, post, and delete* as prefix to map PHP methods to
respective HTTP methods. When they are the only method names they map at
the class level similar to *index* and *default*
GET/POST/PUT/DELETE class_name
GET is the default HTTP method so all public functions without any of
these prefixes will be mapped to GET request. This means functions
*getResult* and *result* will both be mapped to
GET class_name/result
Similarly method *postSomething* will be mapped to
POST class_name/something
For simplicity and making it work out of the box this example is using
a session based fake database, thus depending on a client that
supports PHP Session Cookies. You may use [REST Console](https://chrome.google.com/webstore/detail/faceofpmfclkengnkgkgjkcibdbhemoc#)
an extension for Chrome or [RESTClient](https://addons.mozilla.org/en-US/firefox/addon/restclient/)
a firefox extension.
supports PHP Session Cookies. You may use
[REST Console](https://chrome.google.com/webstore/detail/faceofpmfclkengnkgkgjkcibdbhemoc#)
an extension for Chrome or
[RESTClient](https://addons.mozilla.org/en-US/firefox/addon/restclient/)
a firefox extension.
Alternatively you can use [cURL](http://en.wikipedia.org/wiki/CURL) on the command line.
curl-X POST http://help.luracast.com/restler/examples/_006_crud/index.php/author -H "Content-Type: application/json" -d '{"name": "Another", "email": "[email protected]"}'
{
"name": "Another",
"email": "[email protected]",
"id": 5
}
But since the session wont be working next request wont reflect the
change done by previous request, anyway you get the idea.
.
Example 1: GET author returns
[
Expand Down
66 changes: 51 additions & 15 deletions examples/_006_crud/readme.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<li><a title="Restler Home" href="http://luracast.com/products/restler/">Home</a></li>
<!--<li><a title="Using Restler" href="#">Guide</a></li><li><a title="Restler API Reference" href="#">API</a></li>-->
<li><a class="active" href="../index.html">Examples</a></li>
<li><a title="Share your knowledge by answering user questions in Stack Overflow." href="http://bit.ly/RestlerSupport">Support</a></li>
<li><a title="Share your knowledge by answering user questions in Stack Overflow." href="http://bit.ly/Restler-QA">Support</a></li>
<li><a title="Contribute and Fork Restler on GitHub" href="http://bit.ly/LuracastRestler">GitHub</a></li>
<li><a title="Get updated on Twitter" href="http://twitter.com/Luracast">Twitter</a></li>
</ul>
Expand All @@ -51,12 +51,50 @@ <h3><a href="../index.html">Examples</a></h3>
<h2>CRUD</h2>

<p>Create, Retrive, Update and Delete using
HTTP methods POST, GET, PUT and DELETE respectively.
For simplicity and making it work out of the box it is using
HTTP methods POST, GET, PUT and DELETE respectively.</p>

<p><strong>How the automatic routing is done?</strong></p>

<p>Restler uses <em>get, put, post, and delete</em> as prefix to map PHP methods to
respective HTTP methods. When they are the only method names they map at
the class level similar to <em>index</em> and <em>default</em></p>

<pre><code>GET/POST/PUT/DELETE class_name
</code></pre>

<p>GET is the default HTTP method so all public functions without any of
these prefixes will be mapped to GET request. This means functions
<em>getResult</em> and <em>result</em> will both be mapped to</p>

<pre><code>GET class_name/result
</code></pre>

<p>Similarly method <em>postSomething</em> will be mapped to</p>

<pre><code>POST class_name/something
</code></pre>

<p>For simplicity and making it work out of the box this example is using
a session based fake database, thus depending on a client that
supports PHP Session Cookies. You may use <a href="https://chrome.google.com/webstore/detail/faceofpmfclkengnkgkgjkcibdbhemoc#" target="_blank">REST Console</a>
an extension for Chrome or <a href="https://addons.mozilla.org/en-US/firefox/addon/restclient/" target="_blank">RESTClient</a>
a firefox extension</p>
supports PHP Session Cookies. You may use
<a href="https://chrome.google.com/webstore/detail/faceofpmfclkengnkgkgjkcibdbhemoc#" target="_blank">REST Console</a>
an extension for Chrome or
<a href="https://addons.mozilla.org/en-US/firefox/addon/restclient/" target="_blank">RESTClient</a>
a firefox extension.</p>

<p>Alternatively you can use <a href="http://en.wikipedia.org/wiki/CURL" target="_blank">cURL</a> on the command line.</p>

<pre><code>curl-X POST http://help.luracast.com/restler/examples/_006_crud/index.php/author -H "Content-Type: application/json" -d '{"name": "Another", "email": "[email protected]"}'

{
"name": "Another",
"email": "[email protected]",
"id": 5
}
</code></pre>

<p>But since the session wont be working next request wont reflect the
change done by previous request, anyway you get the idea.</p>

<blockquote>
<p>This API Server is made using the following php files/folders</p>
Expand All @@ -71,15 +109,13 @@ <h2>CRUD</h2>

<p>This API Server exposes the following URIs</p>

<pre><code>GET author ⇠ Author::get()
GET author/:id ⇠ Author::get()
POST author ⇠ Author::post()
POST author/:request_data ⇠ Author::post()
PUT author ⇠ Author::put()
PUT author/:id ⇠ Author::put()
PUT author/:id/:request_data ⇠ Author::put()
DELETE author ⇠ Author::delete()
DELETE author/:id ⇠ Author::delete()
<pre><code>GET author ⇠ Author::get()
GET author/:id ⇠ Author::get()
POST author ⇠ Author::post()
PUT author ⇠ Author::put()
PUT author/:id ⇠ Author::put()
DELETE author ⇠ Author::delete()
DELETE author/:id ⇠ Author::delete()
</code></pre>

<p>Try the following links in your browser</p>
Expand Down
59 changes: 46 additions & 13 deletions examples/_006_crud/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,46 @@ CRUD

Create, Retrive, Update and Delete using
HTTP methods POST, GET, PUT and DELETE respectively.
For simplicity and making it work out of the box it is using

**How the automatic routing is done?**

Restler uses *get, put, post, and delete* as prefix to map PHP methods to
respective HTTP methods. When they are the only method names they map at
the class level similar to *index* and *default*

GET/POST/PUT/DELETE class_name


GET is the default HTTP method so all public functions without any of
these prefixes will be mapped to GET request. This means functions
*getResult* and *result* will both be mapped to

GET class_name/result

Similarly method *postSomething* will be mapped to

POST class_name/something

For simplicity and making it work out of the box this example is using
a session based fake database, thus depending on a client that
supports PHP Session Cookies. You may use [REST Console](https://chrome.google.com/webstore/detail/faceofpmfclkengnkgkgjkcibdbhemoc#)
an extension for Chrome or [RESTClient](https://addons.mozilla.org/en-US/firefox/addon/restclient/)
a firefox extension
supports PHP Session Cookies. You may use
[REST Console](https://chrome.google.com/webstore/detail/faceofpmfclkengnkgkgjkcibdbhemoc#)
an extension for Chrome or
[RESTClient](https://addons.mozilla.org/en-US/firefox/addon/restclient/)
a firefox extension.

Alternatively you can use [cURL](http://en.wikipedia.org/wiki/CURL) on the command line.

curl-X POST http://help.luracast.com/restler/examples/_006_crud/index.php/author -H "Content-Type: application/json" -d '{"name": "Another", "email": "[email protected]"}'

{
"name": "Another",
"email": "[email protected]",
"id": 5
}

But since the session wont be working next request wont reflect the
change done by previous request, anyway you get the idea.
> This API Server is made using the following php files/folders
> * index.php (gateway)
Expand All @@ -17,15 +52,13 @@ a firefox extension
This API Server exposes the following URIs

GET author ⇠ Author::get()
GET author/:id ⇠ Author::get()
POST author ⇠ Author::post()
POST author/:request_data ⇠ Author::post()
PUT author ⇠ Author::put()
PUT author/:id ⇠ Author::put()
PUT author/:id/:request_data ⇠ Author::put()
DELETE author ⇠ Author::delete()
DELETE author/:id ⇠ Author::delete()
GET author ⇠ Author::get()
GET author/:id ⇠ Author::get()
POST author ⇠ Author::post()
PUT author ⇠ Author::put()
PUT author/:id ⇠ Author::put()
DELETE author ⇠ Author::delete()
DELETE author/:id ⇠ Author::delete()


Try the following links in your browser
Expand Down
33 changes: 24 additions & 9 deletions examples/index.html
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<li><a title="Restler Home" href="http://luracast.com/products/restler/">Home</a></li>
<!--<li><a title="Using Restler" href="#">Guide</a></li><li><a title="Restler API Reference" href="#">API</a></li>-->
<li><a class="active" href="index.html">Examples</a></li>
<li><a title="Share your knowledge by answering user questions in Stack Overflow." href="http://bit.ly/RestlerSupport">Support</a></li>
<li><a title="Share your knowledge by answering user questions in Stack Overflow." href="http://bit.ly/Restler-QA">Support</a></li>
<li><a title="Contribute and Fork Restler on GitHub" href="http://bit.ly/LuracastRestler">GitHub</a></li>
<li><a title="Get updated on Twitter" href="http://twitter.com/Luracast">Twitter</a></li>
</ul>
Expand All @@ -42,11 +42,17 @@ <h3><a href="index.html">Examples</a></h3>
<ul><li><a href="_001_helloworld/readme.html" title="Let's say hello!">Hello World</a></li><li><a href="_002_minimal/readme.html" title="Less is more">Minimal</a></li><li><a href="_003_multiformat/readme.html" title="Serving what the client wants">Multi-format</a></li><li><a href="_004_error_response/readme.html" title="Making use of HTTP status codes">Error Response</a></li><li><a href="_005_protected_api/readme.html" title="Creating restricted zone">Protected API</a></li><li><a href="_006_crud/readme.html" title="using POST, GET, PUT and DELETE">CRUD</a></li></ul>
</nav>
<article id="right">
<h2>Examples</h2>
<p>Luracast Restler is a microframework to expose php methods as RESTful API. Best way to learn is by examples,
here you can find the examples that shows every feature of Restler and how to use them.</p>
<p>We have created it in such a way that they can be tested on your local host.</p>
<p>You can check the source code, try some of the API's exposed at the comfort of your browser</p>
<h2>Live Examples</h2>

<p>Luracast Restler is a single file framework that can expose any PHP class (with zero arguments constructor)
and its public and protected methods (that manage their own dependencies) as RESTful API.</p>

<p><strong>Learn by the examples</strong></p>

<p>Here you can find the examples that shows many features of Restler and
how to use them. It is created in such a way that they can be tested
on your local host. You can check the source code, try some of the API's
exposed all at the comfort of your browser</p>
<ol class="toc">
<li><a href="_001_helloworld/readme.html" title="Basic hello world example to get started with Restler 2.0">
<span>Hello World
Expand Down Expand Up @@ -78,14 +84,23 @@ <h2>Examples</h2>
</span> <span class="right">&nbsp;5</span></a></li>
<li><a href="_006_crud/readme.html" title="Create, Retrive, Update and Delete using
HTTP methods POST, GET, PUT and DELETE respectively.
For simplicity and making it work out of the box it is using
a session based fake database, thus depending on a client that
supports PHP Session Cookies">
**How the automatic routing is done?**
Restler uses *get, put, post, and delete* as prefix to map PHP methods to
respective HTTP methods">
<span>CRUD
<small><i>using POST, GET, PUT and DELETE</i></small>
</span> <span class="right">&nbsp;6</span></a></li>

</ol>
<p> </p>
<p> <img src="resources/restler_flow.png" alt="Restler Flow Diagram" title="Restler Flow" width="100%">
<strong>Restler Execution Flow</strong>
</p>
<p> </p>
<p> </p>
<p> </p>
</article>
<footer>
&#169; 2010 <a title="Luracast.com" href="http://luracast.com"><img src="resources/Luracast_dark.png" width="180" height="32" title="Helping Developers with Tools, Utilities, Frameworks and Services"/></a>
Expand Down
Binary file added examples/resources/restler_flow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f8fac79

Please sign in to comment.