Welcome to CaloriesAPI! Here you will find an Application Programming Interface (API) focused on helping people to manage their meals and control the number of calories consumed per day based on NutritionixAPI data that is listed on Public APIs repository.
The CaloriesAPI is a TypeScript RESTful API and the main techologies used for its development were:
- NestJS - Framework;
- ExpressJS - Framework;
- MongoDB - Database;
- Prisma - ORM;
- Jest - Testing Framework;
How does this project uses NutritionixAPI and a MongoDB ReplicaSet cluster. Thus, you must follow these steps:
-
Setting up NutritionixAPI's credentials in a
.env
file- Create a free tier developer account in NutritionixAPI and get your personal credentials
- In the project root, copy the content of
.env.example
, create a file called.env
and pass it to your.env
file.
-
Setting up MongoDB You can choose two ways to setup the application's database:
- With Docker using docker compose (your don't need to change the copied
DATABASE_URL
in.env
):
# starts your mongodb replicaset locally $ docker compose up mongo -d # setup the collections and indexes $ npx prisma db push
- With MongoDB Atlas (free tier):
The easiest way to setup a replica set cluster is using MongoDB Atlas. First, create a MongoDB Atlas instance, update the environment variable
DATABASE_URL
with your instance url adding the paramaterauthSource=admin
(as it is in the.env.example
file). To create your instance using atlas see: Get Started with Atlas
- With Docker using docker compose (your don't need to change the copied
- With Docker:
# watch mode
$ docker compose up api-dev
# production mode
$ docker compose up api-prod
- With a NodeJS package manager:
NOTE: This project was created using the Node package manager Yarn (recommended), but feel free to use NPM or other ones.
# watch mode
$ yarn
$ yarn start:dev
# production mode
$ yarn
$ yarn build
$ yarn start
This project has 100% unit test coverage (ignoring files that cannot be unit tested). To run the tests execute in your command line (CLI):
# unit tests
$ yarn test
# test coverage
$ yarn test:cov
NOTE: If you haven't done before, run yarn
to install the dependencies before testing.
To improve your experience, some simple database seeds of users were created. Run the following command on your CLI:
$ npx prisma db seed
Thinking on practice, use the url: https://www.getpostman.com/collections/91c478d0c1a7b9fd5d9c to import a collection inside your Postman:
Afther that, you need to set the following globals variables on your workspace environment:
main_url
- http://localhost:3000;access_token
;
Done! Now you are ready to use the API locally. Make requests and change the parameters as you go.
- Save public data from NutritionixAPI when getting a response from an user's input;
- Implement an own Natural Language Processing (NLP) to avoid calls to NutritionixAPI;