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
PHPJavaScriptHTML

Avatar of undefined
Last Comment
thready

8/22/2022 - Mon
SOLUTION
Ray Paseur

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
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
Ray Paseur

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
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
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
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......
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
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
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Ray Paseur

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.
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...
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
thready

ASKER
Thanks for your answers! :-)