RESTful Web Services Design of Uber - Hubert
Reference:
1. Uber Developers API
2. Lyft API
3. Google MAP API > Geolocation API
Driver
driver
{
"name": "",
"email": "",
"phone": "",
"password": ""
}
GET
GET /drivers
// response body
// a list
[{}, {}, {}]
GET /drivers/:driverID
// response body
{
"id": 355,
"name": "hubert",
"email": "hongyang.wang@sv.cmu.edu",
"phone": "6502658759",
}
POST
POST /drivers
// request body
{
"name": "hubert",
"email": "hongyang.wang@sv.cmu.edu",
"phone": "6502658759",
"password": "123"
}
// response body
{
"id": 335,
"name": "hubert",
"email": "hongyang.wang@sv.cmu.edu",
"phone": "6502658759",
}
PATCH
PATCH /drivers/:driverID
// request body
{
"name": "hubert wang", //name changed
"email": "hongyang.wang@sv.cmu.edu",
"phone": "6502658759",
}
// response body
{
"id": 335,
"name": "hubert wang",
"email": "hongyang.wang@sv.cmu.edu",
"phone": "6502658759",
}
DELETE
DELETE /drivers/:driverID
Status: 200 / 202 / 204 // success
Passenger
passenger
{
"name": "",
"email": "",
"phone": "",
"password": ""
}
GET
GET /passengers
// response body
[{}, {}, {}] // a list
GET /passengers/:passengerID
// response body
{
"id": 355,
"name": "hubert",
"email": "hongyang.wang@sv.cmu.edu",
"phone": "6502658759",
}
POST
POST /passengers
// request body
{
"name": "hubert",
"email": "hongyang.wang@sv.cmu.edu",
"phone": "6502658759",
"password": "123"
}
// response body
{
"id": 335,
"name": "hubert",
"email": "hongyang.wang@sv.cmu.edu",
"phone": "6502658759",
}
PATCH
PATCH /passengers/:passengerID
// request body
{
"name": "hubert wang", //name changed
"email": "hongyang.wang@sv.cmu.edu",
"phone": "6502658759",
}
// response body
{
"id": 335,
"name": "hubert wang",
"email": "hongyang.wang@sv.cmu.edu",
"phone": "6502658759",
}
DELETE
DELETE /passengers/:passengerID
Status: 200 / 202 / 204
// success
// if not success, return code other than 2XX
Car
car
{
"insurance": true,
"pass#": 12345,
"maker": "BMW",
"model": "BMW 2 series",
"year": 2013,
"license": 12345678,
"door#": 4,
"driverID": 315
}
GET
GET /cars
// response body
[{}, {}, {}] // a list
GET /cars/:carID
// response body
{
"id": 355,
"insurance": true,
"pass#": 12345,
"maker": "BMW",
"model": "BMW 2 series",
"year": 2013,
"license": 12345678,
"door#": 4,
"driverID": 315
}
POST
POST /cars
// request body
{
"insurance": true,
"pass#": 12345,
"maker": "BMW",
"model": "BMW 2 series",
"year": 2013,
"license": 12345678,
"door#": 4,
"driverID": 315
}
// response body
{
"id": 335,
"insurance": true,
"pass#": 12345,
"maker": "BMW",
"model": "BMW 2 series",
"year": 2013,
"license": 12345678,
"door#": 4,
"driverID": 315
}
PATCH
PATCH /cars/:carID
// request body
{
"insurance": false, // changed
"pass#": 12345,
"maker": "BMW",
"model": "BMW 2 series",
"year": 2013,
"license": 12345678,
"door#": 4,
"driverID": 315
}
// response body
{
"id": 335,
"insurance": false, // changed
"pass#": 12345,
"maker": "BMW",
"model": "BMW 2 series",
"year": 2013,
"license": 12345678,
"door#": 4,
"driverID": 315
}
DELETE
DELETE /cars/:carID
Status: 200 / 202 / 204 // success
Ride
ride
{
"pick_up_longitude": 111.11,
"pick_up_latitude": 111.11,
"drop_off_longitude": 111.11,
"drop_off_latitude": 111.11,
"time": "15:10",
"type": "UberX",
"passenger#": 3,
"passengerID": 315,
"driverID": 315
}
GET
GET /rides
// response body
[{}, {}, {}] // a list of rides
GET /rides/:rideID
// response body
{
"rideID": 315,
"pick_up_longitude": 111.11,
"pick_up_latitude": 111.11,
"drop_off_longitude": 111.11,
"drop_off_latitude": 111.11,
"time": "15:10",
"type": "UberX",
"passenger#": 3,
"passengerID": 315,
"driverID": 315
}
POST
POST /rides
// request body
{
"pick_up_longitude": 111.11,
"pick_up_latitude": 111.11,
"drop_off_longitude": 111.11,
"drop_off_latitude": 111.11,
"time": "15:10",
"type": "UberX",
"passenger#": 3,
"passengerID": 315,
"driverID": 315
}
// response body
{
"rideID": 315,
"pick_up_longitude": 111.11,
"pick_up_latitude": 111.11,
"drop_off_longitude": 111.11,
"drop_off_latitude": 111.11,
"time": "15:10",
"type": "UberX",
"passenger#": 3,
"passengerID": 315,
"driverID": 315
}
PATCH
PATCH /rides/:rideID
// request body
{
"rideID": 315,
"pick_up_longitude": 111.11,
"pick_up_latitude": 111.11,
"drop_off_longitude": 111.11,
"drop_off_latitude": 111.11,
"time": "15:10",
"type": "UberPool", // change ride type
"passenger#": 3,
"passengerID": 315,
"driverID": 315
}
// response body
{
"rideID": 315,
"pick_up_longitude": 111.11,
"pick_up_latitude": 111.11,
"drop_off_longitude": 111.11,
"drop_off_latitude": 111.11,
"time": "15:10",
"type": "UberPool",
"passenger#": 3,
"passengerID": 315,
"driverID": 315
}
DELETE
DELETE /rides/:rideID
Status: 200 / 202 / 204
Financial Account
financial_account
{
"billing_name": "Hubert",
"account#": "1234567890",
"exp_date_mon": 08,
"exp_date_year": 19,
"bill_adress": "100 N Whisman Rd, 4113 Central Park Apt at Whisman Station, CA",
"CVC": 085
}
GET
GET /financial_accounts
// response body
[{}, {}, {}] // a list of financial accounts
GET /financial_accounts/: financial_account_ID
// response body
{
"financial_account_ID": 315,
"billing_name": "Hubert",
"account#": "1234567890",
"exp_date_mon": 08,
"exp_date_year": 19,
"bill_adress": "100 N Whisman Rd, 4113 Central Park Apt at Whisman Station, CA",
"CVC": 085
}
POST
POST /financial_accounts
// request body
{
"billing_name": "Hubert",
"account#": "1234567890",
"exp_date_mon": 08,
"exp_date_year": 19,
"bill_adress": "100 N Whisman Rd, 4113 Central Park Apt at Whisman Station, CA",
"CVC": 085
}
// response body
{
"financial_account_ID": 315,
"billing_name": "Hubert",
"account#": "1234567890",
"exp_date_mon": 08,
"exp_date_year": 19,
"bill_adress": "100 N Whisman Rd, 4113 Central Park Apt at Whisman Station, CA",
"CVC": 085
}
PATCH
PATCH /financial_accounts/:account_ID
// request body
{
"billing_name": "Hubert",
"account#": "1234567890",
"exp_date_mon": 08,
"exp_date_year": 19,
"bill_adress": "100 N Whisman Rd, 4113 Central Park Apt at Whisman Station, CA",
"CVC": 000 // CVC changed
}
// response body
{
"financial_account_ID": 315,
"billing_name": "Hubert",
"account#": "1234567890",
"exp_date_mon": 08,
"exp_date_year": 19,
"bill_adress": "100 N Whisman Rd, 4113 Central Park Apt at Whisman Station, CA",
"CVC": 000
}
DELETE
DELETE /financial_accounts/:account_ID
Status: 200 / 202 / 204
Location
POST
Request to Google API, we can get the location of driver / passenger, here I use the example of getting current location.
Reference: Google MAP API > Geolocation API
POST /geolocation/v1/geolocate?key=YOUR_API_KEY
// request body
{
"homeMobileCountryCode": 310,
"homeMobileNetworkCode": 410,
"radioType": "gsm",
"carrier": "Vodafone",
"considerIp": "true",
"cellTowers": [
// See the Cell Tower Objects section below.
],
"wifiAccessPoints": [
// See the WiFi Access Point Objects section below.
]
}
// response body
{
"location": {
"lat": 51.0,
"lng": -0.1
},
"accuracy": 1200.4
}
NEW ADDED AFTER CLASS - HOW TO MANAGE RESOURCES BETWEEN ENTITIES:
-
Financial_Account and Cars should be posted to Driver as resources:
POST /Drivers/:driverID/Cars
POST /Drivers/:driverID/FinancialAccount
- location should be taken as a sub-resource in driver entity
driver
{
"name": "",
"email": "",
"phone": "",
"password": ""
// NEW ADDED AFTER COURSE
location: {
latitude: ,
longtitude:
}
}
-
Ride should be posted to Passenger entity as resources, so the rider can get rides/trips list:
POST /passengers/:passengerID/rides
-
Request a ride:
POST /Rides/:rideID/location
POST /Rides/:rideID/status
GET /Rides/:rideID/quote
GET /Rides/:rideID/locations
GET /Rides/:rideID/finalCost
{
distance
time_call
cost
}
2751