Laravel is accessible, yet powerful, providing powerful tools needed for large, robust applications. A superb inversion of control container, expressive migration system, and tightly integrated unit testing support give you the tools you need to build any application with which you are tasked.
This tutorial will be the first of a two part series for a mobile Tinder-like dating application, focusing on integrating the Sinch SDK in mobile applications to provide Voice, SMS, and Cloud VoIP. For this first part, we will create the REST API that the mobile application will use. This API will be built in Laravel 5.0 using modern development techniques.
Source files for the Tuts+ tutorial: Sinch Integration - Building a REST API with Laravel 5.0
The url for the REST API sessions resource, it's located in the following URL:
- http://YOUR_API_URL/sessions
It has support for the following methods:
- POST - Create an user session
- DELETE/{token} - Destroy an existing user session
Start an user session in the system.
- Endpoint URL - http://YOUR_API_URL/sessions
- Request Method - POST
- Response Format - JSON
- Requires Authentication - No
- Response Codes - 200 | 403
{
"email" : "jdoe@gmail.com",
"fbId" : "USER_FB_ID",
"gender" : "male",
"location" : { "lat" : 37.427208696456866, "lon" : -122.17097282409668 }
"mobile" : "141649811",
"name" : "John Doe"
}
Altough the only required parameters are: fbId and either email or mobile. It's suggested to send all the information, to start a new session the system uses only the email and fbId or the mobile and fbId. However if the user attempting to start a session does not exists, the system will attempt to create a new user record, in order for this to work all the information previously mentioned must be sent.
{
"user_id" : "551335b76803fa1e068b4585",
"user_name" : "John Doe",
"token" : "55136a586803fa1f068b4581"
}
In the case of an unsuccessful request the API will send a 403 error code.
{
"error" : "ERROR_INVALID_PARAMETERS",
"status" : 403
}
Removes an existing user session from the system.
- Endpoint URL - http://YOUR_API_URL/sessions/{token}
- Request Method - DELETE
- Response Format - JSON
- Requires Authentication - Yes
- Response Codes - 200 | 403
{
}
{}
{
"error" : "ERROR_REMOVING_SESSION",
"status" : 403
}
The url for the REST API users resource, it's located in the following URL:
- http://YOUR_API_URL/users
It has support for the following methods:
- GET - Retrieve a list of users
- GET/{id} - Retrieve a single user record
- POST - Create an user in the database
- PUT/{id} - Update an existing user information
- DELETE/{id} - Remove an user record
Removes an existing user record.
- Endpoint URL - http://YOUR_API_URL/users/{id}
- Request Method - DELETE
- Response Format - JSON
- Requires Authentication - Yes
- Response Codes - 200 | 403
{
"token" : "55136a586803fa1f068b4581"
}
{
"_id" : "551335b76803fa1e068b4585",
"email" : "jdoe@gmail.com",
"fbId" : "USER_FB_ID",
"gender" : "male",
"location" : {
type : "Point",
coordinates : [ -122.17097282409668, 37.427208696456866 ]
},
"mobile" : "141649811",
"name" : "John Doe"
}
In the case of an unsuccessful request the API will send a 403 error code.
{
"error" : "PERMISSION_DENIED",
"status" : 403
}
Retrieve a list of existing users in the system.
- Endpoint URL - http://YOUR_API_URL/users
- Request Method - GET
- Response Format - JSON
- Requires Authentication - No
- Response Codes - 200 | 403
{
"distance" : 150000,
"token" : "55136a586803fa1f068b4581"
}
The parameters in the request are optional, for a unregistered user the method will return a list of all the available users in the system.
If a token and distance parameter are given, the system will return the users that are located near the user with the active session at a maximum distance as specified in the request distance parameter, given in meters. The obtained result in a query for a logged in user will exclude the user issuing it.
{
[
{
"_id" : "551335b76803fa1e068b4585",
"email" : "jdoe@gmail.com",
"fbId" : "USER_FB_ID",
"gender" : "male",
"location" : {
type : "Point",
coordinates : [ -122.17097282409668, 37.427208696456866 ]
},
"mobile" : "141649811",
"name" : "John Doe"
}
]
}
In the case of an unsuccessful request the API will send a 403 error code.
{
"error" : "PERMISSION_DENIED",
"status" : 403
}
Retrieve an existing user record from the system.
- Endpoint URL - http://YOUR_API_URL/users/{id}
- Request Method - GET
- Response Format - JSON
- Requires Authentication - Yes
- Response Codes - 200 | 403
{
"token" : "55136a586803fa1f068b4581"
}
The id of the user to retrieve does not need to match the id of the user with the active session, any user can retrieve the details for all the users.
{
"_id" : "551335b76803fa1e068b4585",
"email" : "jdoe@gmail.com",
"fbId" : "USER_FB_ID",
"gender" : "male",
"location" : {
type : "Point",
coordinates : [ -122.17097282409668, 37.427208696456866 ]
},
"mobile" : "141649811",
"name" : "John Doe"
}
In the case of an unsuccessful request the API will send a 403 error code.
{
"error" : "PERMISSION_DENIED",
"status" : 403
}
Create an user record in the system.
- Endpoint URL - http://YOUR_API_URL/users
- Request Method - POST
- Response Format - JSON
- Requires Authentication - No
- Response Codes - 200 | 403
{
"email" : "jdoe@gmail.com",
"fbId" : "USER_FB_ID",
"gender" : "male",
"location" : { "lat" : 37.427208696456866, "lon" : -122.17097282409668 }
"mobile" : "141649811",
"name" : "John Doe"
}
The only optional parameters are the email and mobile, however one of those must be present and is used to start an user session in the system.
{
"_id" : "551335b76803fa1e068b4585",
"email" : "jdoe@gmail.com",
"fbId" : "USER_FB_ID",
"gender" : "male",
"location" : {
type : "Point",
coordinates : [ -122.17097282409668, 37.427208696456866 ]
},
"mobile" : "141649811",
"name" : "John Doe"
}
In the case of an unsuccessful request the API will send a 403 error code.
{
"error" : "ERROR_INVALID_PARAMETERS",
"status" : 403
}
Update an existing user record.
- Endpoint URL - http://YOUR_API_URL/users/{id}
- Request Method - PUT
- Response Format - JSON
- Requires Authentication - Yes
- Response Codes - 200 | 403
{
"gender" : "female",
"name" : "Jane Doe",
"token" : "55136a586803fa1f068b4581"
}
{
"gender" : "female",
"name" : "Jane Doe"
}
In the case of an unsuccessful request the API will send a 403 error code.
{
"error" : "PERMISSION_DENIED",
"status" : 403
}