Link to home
Start Free TrialLog in
Avatar of thready
thready

asked on

REST APIs and their server implementation

Hi Experts,
I'd like to know what to do with a request like this on the server:

http://www.example.com/services/1

This is asking for info about a service whose id is 1.  Great.

Am I missing the name of the PHP page in the URL?  I think not because this is how I've seen these REST APIs described - as resources.  So if I want to use PHP to implement this rest API call, what do I do on the server side?

Thanks, I hope this question makes sense.
Mike
SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of thready
thready

ASKER

Well I know I could do that, I just need to know how it's done when there's no .php in the URL...
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of thready

ASKER

ok.. this is really not what I was hoping for....  Why would everyone preach to use REST APIs and then have to use mod_rewrite...  Maybe my URLs *are* supposed to prepend the PHP page...
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of thready

ASKER

It's just that I've been following a tutorial online that explains that best practices say you should always have this structure, which will make you more scalable, more flexible, more this and that....

GET /photoalbums/italy2012/photos/12345.jpg

photoalbums is always a noun, italy2012 is a specific album

photos is always a noun and 12345.jpg is a specific picture...

They do say that you can use search parameters to get at stuff like this:

GET /photoalbums/japan2010/photos?page=1&page_size=25

I'm just trying to learn the best practice way of doing it, and it surprises me that it would introduce the need for rewriting URLs in order to support a best practice...  I feel I'm still missing something.  Sorry for being hardheaded- I really appreciate your help but I think I might be looking for something more subtle than it's worth.  I hope someone sees what I'm getting at here......
Avatar of thready

ASKER

They say that everything is a resource or collection.  If you have a collection in a collection, the format is as I wrote above ( collection1/iteminCollection1/subcollection/itemInThatSubCollection.  Not sure how much this gives you to follow these guidelines....
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Glad you found a good answer.  The integration of the client-side jQuery is hardly necessary for a RESTful API, but it seems to offer a good client interface.
Avatar of thready

ASKER

It's not the client side part of what this page talks about- it's the mappings they do in php with slim to the functions...
Avatar of thready

ASKER

Thanks for your answers! :-)