Matthew King
Matthew King

Reputation: 13

How to create Rest API with query paramters

I am new to programming and am trying to find some documentation on creating a GET REST API in php that can accept query paramters in the url. I have been looking for documentation and there seems to be a lot out there but not sure what I should focus on. I am looking for the API to take a url like this:

rest.php?format=json&action=courses

Once this url is posted I would like to make a query to my database to retreive the courses. When a url like this is make:

rest.php?format=json&action=students&course=id

I would like to query my database based on parameters set in the url. Can someone please point me in the right direction.

Upvotes: 0

Views: 804

Answers (2)

Fahad Sheikh
Fahad Sheikh

Reputation: 26

There are many aspects that influence the way REST is implemented in the application. Totally depends upon the usecases and the way developer wants it to be, still there are certain REST Standards which will help you to keep your application adhere quality checks.

REST STANDARDS Hope you can use this to relate to your scenario. In the case of query params, they are usually recommended when you can take the risk of exposing the information and is usually used with GET calls. Instead you can use POST call and define the information in payload which can accommodate more data as well there is no risk of exposing information which you don't want.

Hope this clarifies the issue, if not please feel free to ask

Upvotes: 0

Ani
Ani

Reputation: 740

REST specifications are pretty vague in this regard.

However, if you have too many parameters then it is ok to have the method set as POST instead as per best practices.

Upvotes: 2

Related Questions