Integrating RESTFUL api in my application - cakephp

Integrating RESTFUL api in my application.
I've to use restful services in my new project. I'm using CakePHP 2.0.6
I do not want to create a restful services. I've to use restful services.
I want to know is there any ready made component is available in CakePhp to read restful services.
I want that component to serve me the output based on my services by doing the rest in the background.
Additionaly if the component is able to log it then it will be well and good.

A REST API is more a concept than a standard set of protocols, therefore there is no uniform way to interface with the APIs of different providers. Twitter has its own REST API, while Facebook provides another.
Most big webservices provide PHP classes to simplify interfacing with the API. For Twitter there's a third party library called TwitterOAuth and Facebook provides a PHP SDK. These can be loaded as Vendor files in CakePHP. See an earlier answer of mine regarding the loading of vendor files or this older post related to the 1.3 branch of Cake, but still relevant.
Several Cake developers have developed plugins for Cake to interact with popular webservices like the Facebook Plugin by webtechnick. Whereas loading vendor packages is the framework's equivalent of including them like you would in a plain PHP script, loading plugins is a bit different and might simplify things even more (or make them more abstract). The Cake manual entry on plugins has more information.

I've found a PHP Class from http://www.phpclasses.org Which is looks like taking care of most of the REST API part, And it worked for me for my purposes. It has got nice example file which will demonstrate how to use that class.
I've converted this class into Cakephp component. Here is the URL to download the class.
http://www.phpclasses.org/package/5480-PHP-Send-Web-services-requests-to-REST-servers.html

Check out CakePHP's HttpSocket utility. I have not used it yet but I think it's just an API for cURL which sounds like what you need. http://book.cakephp.org/2.0/en/core-utility-libraries/httpsocket.html

Related

Angular JS and Web API Architecture

I have to prepare an architecture with following technologies:
Angular JS 1.5
MVC 5.0/Web API.
EF 6.0
Is it a good option to have a single web project which has angular JS and Web API.
We need to expose web api's to other third party vendors. So, we are thinking to create a separate web api project as a separate project. Need your inputs.
Thanks,
Dhannajay
You can have a lot of options to define the architecture, but to answer your questions, I think is better have separate projects in this case for the following reasons:
You can change the front-end without touch any in the api system (web api) and viceversa
You can scale both sites or only one, maybe, the front-end goes well, but you need more power in the web api, go ahead and scale only the api.
you can do this (like here)
API: your api front end
Core: business logic/EF
MVC: html/mvc/angularjs
DTO: classes/models

How does JS front-end framework (ember, Angular etc.) work with back-end frameworks(such as Django , Rails etc.)?

I have used django for few projects and used heroku to deploy. I have been looking into front-end frameworks such as Ember, Angular and was confused as to how it will integrate with a django project. Reading some Docs, it appears i need to have developed a REST api for my app using the backend framework in order for Javascript framework to communicate with the database. In this case the backend mostly works as a thin layer that provides access to the database. But what if I use something like parse and their Javascript API, would I even need a Backend Framework like Django?
How frameworks like Django will work with frameworks like Angular or Ember depends a lot on what you want to do with it and what your view on architecture is in general, so it's hard to give a one true answer. But in general no, you don't need one, but you still might want one.
You don't need one because as you surmised frameworks like this want a REST API (although it doesn't have to be specifically REST-like that is definitely the most common way of doing it), so you wouldn't be using Django templating or anything like that.
But one of the good part of using these frameworks, and the part that makes the question impossibly to answer, is that they don't care about the backend!
Why does this matter?
When backend and frontend is properly separated you get a great deal more flexibility on both ends. As long as they work with the API you can build them however you see fit. If you find Djangos ORM nice to work with you can use it to create the API. If you feel like using something super lightweight like Flask you can do that. If you want to host a Java app on AWS you can do that, etc, etc.
The key is that you can let your backend needs determine how you build the backend, and your frontend needs determine how you build the frontend. That's why the question can't be answered. You strictly speaking don't need Django or any smilar framework but depending on what the backend is going to do you might want some of the features from them, like the ORM or the general structure.
So look at what your backend needs to do in order to serve the API and choose based on that.

Meteor, Laravel RESTful API + AngularJS or Laravel for my next web app

I have a PHP background and I have build several web apps with Laravel (3 and 4). I have also experience of using RESTful APIs in my projects.
My current client have an ERP which is bunch of PHP files. Those files contains about 60K lines of spaghetti code. Client doesn't want to invest more money for developing that system so we decided to rewrite the whole app. I know all the risks about rewrite and I have also read Joel's article (http://www.joelonsoftware.com/articles/fog0000000069.html) so there is no need for refactor or rewrite discussion.
For the new app I have been thinking to build RESTful API with Laravel (4 or 5) and frontend with AngularJS. That was before I tested Meteor 1.0. It is very promising and it would be very nice to use it for this project. But is it suitable for this kind of product?
My client's product is something like this:
No public registration for this app (admin creates all the users)
Complex user permissions (group level permissions and user level permissions, 6 groups)
File handling (images, pdf etc.). Files are used as message attachments.
Big data tables
External API calls
App contains sections like: users, orders, offers, time tracking, sales, reporting, calendars, clients.
So is it wise to use Meteor for this kind project or do you prefer RESTful API + AngularJS combo? I'm hesitating because I'm afraid that in big projects using Meteor the code will becode mess.
I'm working on a feasibility analysis for using meteor on a similar project at Google, and I think Meteor would be great for your project.
Admin user creation - check Houston
REST API - [you don't need one for your own tools]( need to think in Meteor terms. ). Meteor has a much simpler mechanism - Meteor.call and Meteor.methods.
User permissions - see the roles package
File handling - see CollectionFS or search Atmosphere for upload.
External API calls - HTTP.get makes it trivial. See also Atmosphere for specific packages.
Big data tables - see this answer about table widgets
Don't know much about Meteor, but for the Angular variant you can take a look at this POC application using a AngularJS client and a REST Server:
https://groups.google.com/forum/#!topic/angular/Q3GrhAH39AU
http://www.civilian-framework.org/doc-samples.html#crm

extjs clarification

In this link: http://www.sencha.com/blog/spotlight-ext-js-customers/
Please scroll to the section :Why We Chose Ext JS
There is this line :
By using Ext JS, we lowered the cost
of developing a Web services API.
But I do not really get the explanation. How cost of developing a Web services API can be lowered by a client side framework?
I don't think the explanation conveys what the author intended. I think they were enthusiastic about ExtJs's AJAX APIs, which are easy to work with and can be called using a number of GUI components (which they mention).
The AJAX and component APIs do not create a server-side Web service API for you though, which their testimonial leads you to believe by saying:
This gives us the benefit of exposing
these same AJAX (JSON) calls, as a
Web services API, to our customers...
By using Ext JS, we lowered the cost
of developing a Web services API.
Well not quite, ExtJs doesn't create a Web Services API for you; it creates a method of interacting with your custom REST (or whatever) API. Although maybe they meant that since ExtJs defines how the client should interact with the server, via their numerous components, their server-side services were easier to create. For instance, ExtJs makes it easy to work with REST webservices, and it defines expectations in callbacks, etc. So in ExtJs providing the client solution, it was easier to devise a server solution (the webservices API) given half of a contract.

How to design an extensible CMS for Google App Engine?

I am a fan of the extensibility of the CMSes. You can upload some code (usually PHP), authorize it from the CMS admin panel and it's running.
I wonder if it is possible in Google App Engine. I haven't checked the extensibility of existing CMSes for Google App Engine, but if there is any of them that supports plugins I would like to know how they did it, and whether they are JS plugins only, or if they support Python/Java plugins too.
Nick Johnson from Google wrote an entire blog post series on how to write a blog system for app engine. If it doesn't do what you want, I am sure that you can extend it but normally a blogging system is sufficient for a CMS for most people.
I don't have a public example to point to (sorry), but I can confirm that it is possible to create Python plugins for an App Engine project. I completed a project a few months ago that does something like this. The crux of the thing comes down to a single line of python:
exec plugincode in someDict
Above 'plugincode' is a string containing some python code to execute, and someDict is a dictionary of globals to execute it in. This is arguably cleaner than using eval(). In our case the globals dictionary contained an instance of an object that the plugincode used to communicate with the system. I can't think of any major limitations with this (or similar) approaches. e.g. plugincode could declare a class, and register an instance of that class as a callback handler etc etc.
In our case we stored the plugin code in the Data Store, and loaded it at appropriate times (e.g. when an instance of the app is started).
Actually I see no conceptual problem with supporting plugins in App Engine application. For example on Java you may fetch plugin jar to memory from data store or memcache (on application initialization phase), and then use custom class loader to load plugin classes as needed). Actually you even may load classes from request data and evaluate them on the fly if needed (how we do it in AppWrench Java console).
Regards,
Pavel.

Resources