PHP Rest API Framework SLIM to Create REST API – 2

In last post we were using PHP Rest API Framework SLIM to create a simple REST API for our android application. In the last post I have created the student registration and student login part. Now …

php rest api framework slim to create rest api

In last post we were using PHP Rest API Framework SLIM to create a simple REST API for our android application. In the last post I have created the student registration and student login part. Now in this post we will complete our REST API.

If you haven’t gone through the last PHP Rest API Framework Tutorial, then you should first check that. You can go to my last PHP Rest API Framework tutorial from the link given below.

PHP Restful API Framework SLIM to Create REST API – 1

In the last post I have already explained the codes. So I will not be explaining codes here. We will add more codes only. But before showing you the codes I will show you the final API that is already created.

The final REST API

In the below table you can see all the URL paths with the request method and required parameters.

URL Method Parameters
/createstudent POST name, username, password
/studentlogin POST username, password
/createfaculty POST name, username, password, subject
/facultylogin POST username, password
/createassignment POST name, details, facultyid, studentid
/assignments/:id GET student api key
/students GET faculty api key
/submitassignment/:id PUT faculty api key

I am using wamp server and the location to my API  is.

http://localhost/StudentApp/v1

Response of Requests

These are the success response of every call.

http://localhost/StudentApp/v1/createstudent

http://localhost/StudentApp/v1/studentlogin

http://localhost/StudentApp/v1/createfaculty

http://localhost/StudentApp/v1/facultylogin

http://localhost/StudentApp/v1/createassignment

http://localhost/StudentApp/v1/assignments/2

In the above URL 2 is the student id.

http://localhost/StudentApp/v1/students

http://localhost/StudentApp/v1/submitassignment/3

Here 3 is the assignment id.

Updating the Existing Code

So I explained the whole API, now its time to write code to create the above explained API. So the main modification (actually addition of codes) will be done on DbOperation.php and index.php files.

So first come to DbOperation.php and write the following code.

Updating DbOperation.php

Updating index.php

Now thats it, You can try testing your API.

PHP Rest API Framework SLIM Tutorial Source Code and Configuration

If you are still facing trouble in this PHP Rest API Framework Tutorial, then don’t worry here I am giving you the complete source code. And in the video you can see how you can download and configure the source code to your system. First download the source code from the link given below. And then watch the video.

[sociallocker id=1372] Restful API PHP Download [/sociallocker]


So thats all for this PHP Rest API Framework SLIM tutorial guys. In the next part we will create an Android Application using this API. If you like my posts then please share the post among your circles. Thank You 🙂

Hi, my name is Belal Khan and I am a Google Developers Expert (GDE) for Android. The passion of teaching made me create this blog. If you are an Android Developer, or you are learning about Android Development, then I can help you a lot with Simplified Coding.

Expand Your Knowledge: Next Tutorial Picks

0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x