Igniting your web service - EECI2009

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    3 Favorites

    Igniting your web service - EECI2009 - Presentation Transcript

    1. Igniting your web-service Using CodeIgniter and REST to share information between applications, servers and services. Phil Sturgeon email@philsturgeon.co.uk http://twitter.com/philsturgeon http://philsturgeon.co.uk http://github.com/philsturgeon
    2. What the hell is REST? An easy way to transfer data between client(s) & server Provides data in XML, JSON, HTML, CSV... pretty much anything depending on what HTTP Accept header you send. Works over HTTP GET, POST, PUT and DELETE Not a technology, more of a convention
    3. That sounds just like... XML-RPC
    4. That sounds just like... XML-RPC SOAP
    5. That sounds just like... XML-RPC JSON-RPC SOAP
    6. That sounds just like... XML-RPC Request SOAP Response JSON-RPC
    7. That sounds just like... XML-RPC Request SOAP Response JSON-RPC
    8. That sounds just like... XML-RPC Request { “method": "sayHelloTo", "params": "to" : ["my little friend"], "id": 1} SOAP Response { "result": "Say hello to: my little friend!", "id": 1} JSON-RPC
    9. So how does REST do it? Request http://twitter.com/users/show/philsturgeon HTTP Accept: application/json Responce { "verified":false, "profile_background_tile":false, "description":"I work as a developer for @HargLansdown and use my spare time to develop, write articles about programming and create slightly intoxicated screencasts.", "profile_background_color":"024d68", ...etc }
    10. What’s this got to do with CodeIgniter? CodeIgniter is the perfect match for creating and ingesting REST Strong OOP architecture Use existing models and libraries Use ActiveRecord and ORM Validate POST requests with Form_validation
    11. Average CodeIgniter architectures One (or two) servers Database CodeIgniter frontend models run database queries Models need to know if they are looking at MySQL, MSSQL, Oracle, etc. Frontend Makes scalability tricky
    12. API based architecture Flexible server architecture Database Use it for desktop apps or Mobile Apps mobile applications Public API already created (optional) CodeIgniter Desktop Apps REST API Business logic central Frontend no longer database dependant Performance - Implement Frontend Third-party sites basic caching on API layer
    13. Case study HargreavesLansdown http://h-l.co.uk/
    14. Objects and data access for constructing web pages Case study Author: James Tyrrell Last updated: 03/04/07 Database Broker Focus MySQL MS SQL servers HargreavesLansdown Data abstraction TCF components creole Creole: Provides a unified set of methods for interacting with databases Middleware Remote Remote Object servers functions Models Remote SOAP REST Data server class Classes Classes transport HTTP POST SOAP Call RESTful GET Posts requests to the middleware Remote SOAP and unserializes the results it gets client class Client back. Contain the application logic for the Business Front-end CMS, Smarty, error logging, logic classes business processes, email, user security, etc. Web server Other Page Systems Atlas constructor (default.php) Presentation layer Page processors: Contain code required to build the content of a module (e.g. fund data, news headlines) and output to Smarty Page processors templates. Contains module- level logic (e.g. to switch between steps in a process). Stored in the section directories. http://h-l.co.uk/ Subscripts & templates: Stored Subscripts and templates in the /inc & /tpl sub-folders of each section
    15. Objects and data access for constructing web pages Case study Author: James Tyrrell Last updated: 03/04/07 Database Broker Focus MySQL MS SQL servers HargreavesLansdown Data abstraction TCF components creole Creole: Provides a unified set of methods for interacting with databases Middleware Remote Remote Object servers functions Models Remote SOAP REST Data server class Classes Classes transport HTTP POST SOAP Call RESTful GET Posts requests to the middleware Remote SOAP and unserializes the results it gets client class Client back. Contain the application logic for the Business Front-end CMS, Smarty, error logging, logic classes business processes, email, user security, etc. Web server Other Page Systems Atlas constructor (default.php) Presentation layer Page processors: Contain code required to build the content of a module (e.g. fund data, news headlines) and output to Smarty Page processors templates. Contains module- level logic (e.g. to switch between steps in a process). Stored in the section directories. http://h-l.co.uk/ Subscripts & templates: Stored Subscripts and templates in the /inc & /tpl sub-folders of each section
    16. Objects and data access for constructing web pages Case study Author: James Tyrrell Last updated: 03/04/07 Database Broker Focus MySQL MS SQL servers HargreavesLansdown Data abstraction TCF components creole Creole: Provides a unified set of methods for interacting with databases Middleware Remote Remote Object servers functions Models Data transport CodeIgniter Remote server class SOAP Classes REST Classes REST API HTTP POST SOAP Call RESTful GET Posts requests to the middleware Remote SOAP and unserializes the results it gets client class Client back. Contain the application logic for the Business Front-end CMS, Smarty, error logging, logic classes business processes, email, user security, etc. Web server Other Page Systems Atlas constructor (default.php) Presentation layer Page processors: Contain code required to build the content of a module (e.g. fund data, news headlines) and output to Smarty Page processors templates. Contains module- level logic (e.g. to switch between steps in a process). Stored in the section directories. http://h-l.co.uk/ Subscripts & templates: Stored Subscripts and templates in the /inc & /tpl sub-folders of each section
    17. Serving REST content in CodeIgniter http://github.com/philsturgeon/codeigniter-restserver
    18. How does it work? <?php require(APPPATH.'/libraries/REST_Controller.php'); 1x REST_Controller.php class Example_api extends REST_Controller { function user_get() { 1x (or more) API controllers $user = $this->user_model->get_user( $this->get('id') ); if(!empty($user)) { HTTP method based methods $this->response($user, 200); // 200 being the HTTP response code } else { Normal CodeIgniter stuff } $this->response(NULL, 404); } $this->response($data) function user_post() { $result = $this->user_model->update( $this->post('id'), $_POST ); $this->response($result, 200); // 200 being the HTTP response code } ?>
    19. Quick CodeIgniter REST API recap Building an API can be useful for small and big sites alike Build your data interaction code once, use it everywhere Use ActiveRecord and ORM over standalone abstraction layers Keep your application independent of the data source via the API.
    20. Who else is doing it?
    21. Making REST requests in CodeIgniter http://github.com/philsturgeon/codeigniter-restclient
    22. Integration with “2.0” services you say? VERY Basic Example $this->load->library('rest', array( 'server' => 'http://twitter.com/' )); $result = $this->rest->get('users/show/philsturgeon'); This GET’s all data from http://twitter.com/users/show/philsturgeon and detects what format it is being returned in. It spots it is XML and parses it accordingly.
    23. Integration with “2.0” services you say? More complicated example $this->load->library('rest', array( 'server' => 'http://twitter.com/', 'http_user' => 'philsturgeon', 'http_pass' => 'password' )); $params = array( 'status'=> 'Run, @dallard’s robots are attacking!' ); $result = $this->rest->post('statuses/update.xml', $params); Posts a new message as the user provided.
    24. Summary REST API’s mean you can run actions on other services, websites and applications. i.e: Do almost anything on Twitter, Flickr and Facebook that you can do on the site. Can replace your models with REST requests, or implement to libraries.

    + philsturgeonphilsturgeon, 1 month ago

    custom

    681 views, 3 favs, 8 embeds more stats

    Using CodeIgniter and REST to share information bet more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 681
      • 526 on SlideShare
      • 155 from embeds
    • Comments 0
    • Favorites 3
    • Downloads 20
    Most viewed embeds
    • 93 views on http://eeci2009.com
    • 54 views on http://www.eeci2009.com
    • 3 views on http://webtech.wordpress.com
    • 1 views on http://www.republiclabs.com
    • 1 views on http://eeci2010.com

    more

    All embeds
    • 93 views on http://eeci2009.com
    • 54 views on http://www.eeci2009.com
    • 3 views on http://webtech.wordpress.com
    • 1 views on http://www.republiclabs.com
    • 1 views on http://eeci2010.com
    • 1 views on http://www.eeci2010.com
    • 1 views on http://hetal.wordpress.com
    • 1 views on http://philsturgeon.co.uk

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories