GithubHelp home page GithubHelp logo

swapi-favs-nestjs's Introduction

Description

SWAPI API based favorites app (backend) built using Nest.

Requirements

  • Node v18.14.1
    • [Optional] Install nvm to help manage node versions.
  • Docker to help with the DB and redis containers.

Installation

$ 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`.

Docs and notes

Please do go through docs once before you start. :)

Running the app

# 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

APIs

  • [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.

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

Pending

  • Architecture and design flowcharts/diagrams
  • Better code documentation.

License

MIT license.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.