Fist up, I've never made a web service before. This will be apparent in the following question!
We have a web application (All written in PHP) that requires a web service for communicating with other systems and websites. This site was written a while ago and is loosely based on the MVC design pattern.
The application is quite large, and works like a restful web service already. Each page is generated by calling the main page with arguments telling it which page to render. The arguments tell the main page the location of the main PHP file (used for producing all the XML for the page) and the XSL template for that page. Using these arguments the main page handles the XSL-T and displays the resulting page.
I believe that a web service should be almost a separate system from the main application. It's sole function should be to receive requests (either via SOAP message, or HTTP for restful services) and take action on them, in this case returning requested information from the databse in XML format or by adding information to the database.
However I'm being told by other people (who's opinion I don't really respect if I'm honest) that the web service should be built into the main page used by the application to render pages. Personally I feel this would remove some of the ambiguity of how the system works (possibly leading to security issues) and will result in a massive main page which will be difficult to maintain as it will be used for both the web service and application page generation.
Which method is the correct way? Am I barking up the wrong tree completely? Does anyone recommend web sites or books that can help on the matter?
Thanks in advance for responses!
Web Service - Have I got the wrong Idea?
Moderator: General Moderators
-
marty pain
- Forum Contributor
- Posts: 105
- Joined: Thu Jun 11, 2009 5:32 am
- Location: Essex
Re: Web Service - Have I got the wrong Idea?
At first read, it sounds like you are both right, and both wrong. 
a Web Service is simply an application service that operates via the WWW (or at least over some form of network)
a RESTful service is not one that has one page with query string parameters to dictate the action of the service. No sir, that is an RPC service!
There is little reason for (X)HTML pages to be considered outside of a Web Service. They are, after all, a service on the web. If you look at the fundamentals, they both do the exact same thing. Send a request to a service, and get a response back. It just so happens that the body of the response is render-able by a user agent.
As for separation of Web Service from "main application" then, yes to a degree. A Web Service should interact with the application through an interface to garner data, then format that data appropriately and respond to the request. But then, that's just how every object should interact with every other object, anyway.
a Web Service is simply an application service that operates via the WWW (or at least over some form of network)
a RESTful service is not one that has one page with query string parameters to dictate the action of the service. No sir, that is an RPC service!
There is little reason for (X)HTML pages to be considered outside of a Web Service. They are, after all, a service on the web. If you look at the fundamentals, they both do the exact same thing. Send a request to a service, and get a response back. It just so happens that the body of the response is render-able by a user agent.
As for separation of Web Service from "main application" then, yes to a degree. A Web Service should interact with the application through an interface to garner data, then format that data appropriately and respond to the request. But then, that's just how every object should interact with every other object, anyway.
-
marty pain
- Forum Contributor
- Posts: 105
- Joined: Thu Jun 11, 2009 5:32 am
- Location: Essex
Re: Web Service - Have I got the wrong Idea?
Thanks!
Any recommendations of things to read? I have read a number of websites but would like something from a reliable source.
I was planning to use some of the objects of the main application but not the application itself (if you see what I mean). Is this what you mean by separation to a degree? I kind of see them as two separate applications that use the same objects to access the information in the database. What they do after that is very different.
Any recommendations of things to read? I have read a number of websites but would like something from a reliable source.
I was planning to use some of the objects of the main application but not the application itself (if you see what I mean). Is this what you mean by separation to a degree? I kind of see them as two separate applications that use the same objects to access the information in the database. What they do after that is very different.
Re: Web Service - Have I got the wrong Idea?
This should get you started - http://www.slideshare.net/bngsudheer/bu ... -using-php
Developing a REST API is not much different from normal development. Just instead of returning HTML pages you are returning structured data in various formats (XML, JSON etc) and use URIs to organize actions and methods (some use that approach to develop regular sites as well)
Developing a REST API is not much different from normal development. Just instead of returning HTML pages you are returning structured data in various formats (XML, JSON etc) and use URIs to organize actions and methods (some use that approach to develop regular sites as well)
Re: Web Service - Have I got the wrong Idea?
Returning HTML pages is perfectly fine in a RESTful service. You will only receive GET and POST from a browser, though. However for the rest of the service, actions should be defined by the HTTP method (also known as 'verb') i.e. GET, DELETE, POST, PUT, etc. and not by the uri. Example:
All have the same uri, but all have very different actions.
What content type you return should be defined by the request's "Accept" header, usually one of "application/xhtml+xml", "application/xml" or "application/json".
The definitive book on RESTful Web Services has the same name.. RESTful Web Services
Code: Select all
GET /user/1 HTTP/1.1
DELETE /user/1 HTTP/1.1
PUT /user/1 HTTP/1.1
POST /user/1 HTTP/1.1
What content type you return should be defined by the request's "Accept" header, usually one of "application/xhtml+xml", "application/xml" or "application/json".
The definitive book on RESTful Web Services has the same name.. RESTful Web Services
Re: Web Service - Have I got the wrong Idea?
Just as a tip that might save you some headaches later on concerning which format to use. JSON is excellent (not to mention lighter) in controlled situations where you aren't likely to run into "messy" data. However if there's the possibility of running into floating quotations (ie: you're developing using someone elses database) you can find your JSON breaking down pretty fast, and its not always practical (or efficient) to be doing checks and str_replace or regex on your results.various formats (XML, JSON etc)
In short, I use JSON for myself, XML for user-supplied data.