In the introduction you saw the overview of what we’ll build. We need to manage a list of trips, and we need to track expenses for each of those trips.
Let’s now dissect this into details, and translate it into a series of API endpoints.
An endpoint is a unique URL we will call to create an operation.
Like adding a new trip with its name.
If you are unfamiliar with how HTTP works, take the time to read my tutorials on the HTTP protocol and how HTTP requests work.
At the beginning, there is no trip stored, and we need to add one. I imagine the app will ask the user for the name, and there will be a “Create trip” button. When clicked, the app will send the name to us, to the /trip
endpoint with the POST
HTTP method.
We have our first endpoint, which will accept a name
property.
POST /trip { name }
Another endpoint will list the trips, and it’s
GET /trips
By default, it will return the trips ordered by creation date.
When the user wants to add a new expense, the app will invoke the /expense
endpoint with the POST method, with some parameters that describe the expense
POST /expense { trip, date, amount, category, description }
trip
is the ID of the currently selected trip.
category
is the name of the category of the expense. We’ll provide a list of categories to choose from, which is static: travel
, food
, accomodation
, fun
.
When we want to retrieve a trip expenses, we call the /expenses
endpoint with the GET method:
GET /expenses { trip }
passing the trip
identifier.