...

/

Setting Up the Environment of Our Final Application

Setting Up the Environment of Our Final Application

Learn how to use the REST API from AWS.

We’re ready for our final hands-on! We’ll again write a relatively complete application, this time with some more emphasis on test-driven development, communicating with the outside world, and storing data.

REST API

For this application, we’ll handle hotel reservations. We’ll expand our range compared to the previous project, in that we’ll now have a REST API and will be saving data in a database. Everything will once again be deployed in the AWS Cloud.

We’ll leave a few things out of the picture, though. We won’t be handling user registration and authorization. Furthermore, we don’t have the time to write a frontend (such as a website). That would only distract us from our goal, which is writing functional TypeScript code, though the React framework has a very functional feel to it. It encourages the use of pure functions and the creation of applications out of smaller components (like buttons and lists). So, in spirit, it will certainly play nice with a functional backend.

We’ll also start expanding our project as we go. Let’s begin with an endpoint that receives reservation requests. Because we’re changing data, the proper HTTP method for adding a reservation is POST. We’re expecting the obvious stuff, including a hotel, start and end dates, and the reservation date. The end date is when checkout is required, making the room free again sometime that same day. We’ll also receive a user’s ID, which we’ll pretend has been sent along with the request by our authentication service. Our system will verify the received information, look the hotel up, and make the reservation.

Setting up the environment

Let’s do some setup. Obviously, we need a new empty project. We add a package.json in the root of the project:

Press + to interact
{
"name": "leanpub-reservations",
"version": "1.0.0",
"description": "Example reservations project with fp-ts and aws",
"scripts": {
"build-all-local": "lerna clean -y && lerna exec -- npm ci",
"build-all": "lerna exec -- npm run build",
"test-all": "lerna exec -- npm run test"
},
"dependencies": {},
"devDependencies": {
"jest": "^26.5.2",
"ts-jest": "^26.4.1",
"typescript": "^4.0.3",
"ts-loader": "^5.3.3",
"webpack": "^5.3.0",
"webpack-cli": "^4.1.0",
"lerna": "^3.22.1"
},
"author": "Sam Van Overmeire",
"license": "ISC"
}

Some of this will look familiar. We added a bunch of dev dependencies that we’ll need at some point. New among these is ...