-
Notifications
You must be signed in to change notification settings - Fork 48
API Design
We made the design of our API using Apiary. Apiary is a tool that lets you create a blueprint of your API and lets your teammates test the API using Apiary's mock data server without you having to implement the actual API. This speeds up the development of a product considerably.
To get started, you need to sign in using your GitHub account. After you sign in, you can start writing your API's blueprint which will look something like this:

As shown in the image above, you can specify the routing for your API. For example, when someone does a Get request to the root of our API he will get a JSON response specifying the urls for the different requests he can make using our API.
Another nice thing about Apiary is that as you go writing the blueprint, Apiary will automatically create a documentation for it. To see our documentation click here. From there anyone can make a call to the mock server which is another nice feature in Apiary.
We have six API calls which are as follows:
This call API call is is a Get call that will return a JSON object with a list of all the cars.The list of cars is gotten from data the MySQL server, passed to SQLAlchemy to be put into a json object, then is passed through flask to the requester. This list of cars are going to be then handled by the AngularJS code to produce the required sorting and pagination.
A sample API call:
GET http://sweetrides.me/api/get_cars
A sample response:
[
{
"year":2016,
"id":1,
"horsepower":201,
"make":"acura",
"model":"ilx",
"price":31890.0,
"img_url":"http://ts2.mm.bing.net/th?id=OIP.M7656c6f6aaa4d51c3ddee4b1192adeeeH0&pid=15.1"
},
{
"year":2016,
"id":2,
"horsepower":279,
"make":"acura",
"model":"rdx",
"price":40370.0,
"img_url":"http://ts4.mm.bing.net/th?id=OIP.M9e8c70aff2632ee58fc97806bf5b83ffH0&pid=15.1"
},
...
]
This API call returns only a single Car json object or a 404 Exception if the specified ID is not in the cars database.
A sample API call:
`GET http://sweetrides.me/api/get_car/1`
A sample response:
`{ ` `"year":2016,` `"id":1,` `"horsepower":201,` `"make":"acura",` `"model":"ilx",` `"price":31890.0,` `"img_url":"http://ts2.mm.bing.net/th?id=OIP.M7656c6f6aaa4d51c3ddee4b1192adeeeH0&pid=15.1"` `}`
This API call is also a Get call that will return a JSON object with a list of all the manufacturers. As with the previous API calls, all the manufacturers will be handed to the front-end and then AngularJS will take care of the sorting and pagination.
A sample API call:
GET http://sweetrides.me/api/get_manufacturers
A sample response:
[
{
"num_models":3,
"id":1,
"max_car_id":104,
"name":"chrysler",
"avg_horsepower":291.3333333333333,
"avg_price":32971.666666666664,
"img_url":"http://www.carlogos.org/uploads/car-logos/Chrysler-logo-1.jpg"
},
{
"num_models":8,
"id":2,
"max_car_id":152,
"name":"honda",
"avg_horsepower":190.625,
"avg_price":27965.0,
"img_url":"http://www.carlogos.org/uploads/car-logos/Honda-logo-1.jpg"
},
...
]
This API call is also a Get call that will return a single JSON object with the specified manufacturer, or a 404 Error if there is not one.
A sample API call:
GET http://sweetrides.me/api/get_manufacturer/1
A sample response:
{
"num_models":3,
"id":1,
"max_car_id":104,
"name":"chrysler",
"avg_horsepower":291.3333333333333,
"avg_price":32971.666666666664,
"img_url":"http://www.carlogos.org/uploads/car-logos/Chrysler-logo-1.jpg"
}
This API call is also a Get call that will return a JSON object with a list of all the engines. As with the previous API calls, all the engines will be handed to the front-end and then AngularJS will take care of the sorting and pagination.
A sample API call:
GET http://sweetrides.me/api/get_engines
A sample response:
'['
'{'
'"id": 0,'
'"name": "3.0L V6 24 Valve Supercharger Gas Premium Unleaded (required)",'
'"cylinder": 6,'
'"horsepower": 333,'
'"torque": 325,'
'"fuelType": "premium unleaded (required)"'
'},'
'{'
'"id": 1,'
'"name": "Erb",'
'"cylinder": 6,'
'"horsepower": 295,'
'"torque": 262,'
'"fuelType": "flex-fuel (unleaded/E85)"'
'}'
'...'
']'
This API call is also a Get call that will return a single JSON object with the specified engine, or a 404 Error if there is not one.
A sample API call:
GET http://sweetrides.me/api/get_engine/1
A sample response:
'{'
'"id": 1,'
'"name": "Erb",'
'"cylinder": 6,'
'"horsepower": 295,'
'"torque": 262,'
'"fuelType": "flex-fuel (unleaded/E85)"'
'}'