SWAPI API based favorites app (backend) built using Nest.
- Node v18.14.1
- [Optional] Install
nvm
to help manage node versions.
- [Optional] Install
- Docker to help with the DB and redis containers.
$ npm install
Copy the .env.template
file into .env
and .env.test
files.
$ cp .env.template .env
$ cp .env.template .env.test
$ # Append "-test" to `POSTGRES_DBNAME` in `.env.test`.
Please do go through docs once before you start. :)
# Spin up the third-party containers
$ docker compose up -d
# Create the test db
$ docker exec -it swapi-favs-postgres sh -c 'psql -U $POSTGRES_USER -c "CREATE DATABASE \"${POSTGRES_DB}-test\""' # or replace ${POSTGRES_DB}-test with your DB name in .env.test
# Migrate the DB
$ npx prisma migrate deploy
# Generate the prisma library
$ npx prisma generate
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
- [Create users]
curl --location --request POST 'http://localhost:3000/users/'
- [Add favorite]
curl --location 'http://localhost:3000/favorites/' --header 'user-id: e251c7db-27e1-49e6-816e-6550e2107ab4' --header 'Content-Type: application/json' --data '{ "favorites": [ { "id": "https://swapi.dev/api/films/1/", "type": "Movie", "label": "An old hope" } ] }'
- [Get planets]
curl --location 'http://localhost:3000/planets/?search=BHARAAN' --header 'user-id: 63717ed2-cfbc-405d-9baf-f2b30c11d360'
- [Get movies]
curl --location 'http://localhost:3000/movies/?search=few' --header 'user-id: 63717ed2-cfbc-405d-9baf-f2b30c11d360'
APIs are available via a postman collection (./postman-collection.json)
Use the "create user" API to create a new user.
Change the
user-id
in the GET API headers to the user-id created in the "create user" API.
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
- Architecture and design flowcharts/diagrams
- Better code documentation.
MIT license.