.NET-based application that serves as a platform for managing and retrieving cooking recipes.
A live version of a web app using the API can be found here and the repository for the front end here.
- Recipe management: Read and delete operations for recipes (update, delete and creation work in progress).
- Search Functionality: Search for recipes by name, difficulty, only vegetarians and ingredients.
- Difficulty Level: Assign difficulty levels to recipes.
- Getting Started
- Prerequisites
- Running without Docker
- Running with Docker
- API Documentation
- Postman Collection
- Testing
- .NET SDK
- PostgreSQL at least. 9.6
If installing with Docker:
-
Clone the repository:
git clone https://github.com/luz-ojeda/cook-api.git
-
Navigate to the project's root directory
cd cook-api/CookApi
Inside the appsettings.Development.json
file, locate the ConnectionStrings
property and update DefaultConnection
with your database's own connection string.
{
"ConnectionStrings": {
"DefaultConnection": "Host=localhost;Username=YourUsername;Password=YourPassword;Database=YourDatabase;"
},
// ...
}
-
Apply migrations
dotnet restore dotnet ef database update
-
Run the API
dotnet run
-
Clone the repository:
git clone https://github.com/luz-ojeda/cook-api.git
-
Create a
db
folder in root with your PostgreSQL password in apassword.txt
file inside. Adb-password
secret is defined in thecompose.yaml
file, the db service will retrieve the PSQL password from this secret. -
Build and run with Docker Compose
docker-compose up --build
This command will create and start two Docker containers. One for the PostgreSQL database and another one for the API as specified in the
compose.yaml
file. The--build
flag ensures that Docker Compose builds the necessary images.The API is configured to receive requests on localhost port 8080.
- SQL Scripts for Initial Data: Inside
SqlScripts/
you can find some scripts to insert initial sample recipes and ingredients into the database if you desire. These are run automatically in the containerized application on the db startup.
This API is self-documented using Swagger. With the project running, you can access the API documentation by navigating to:
http://localhost:5255/swagger
without Docker or
http://localhost:8080/swagger
with Docker
There is a Postman collection available, though it is for local testing only. URL variable can be found in the collection scope set to http://localhost:5255
, the .NET default url when running with dotnet run
Tests can be found in the CookApi.Tests
project.
Integration tests rely on a PostgreSQL database that is created on runtime and deleted after all tests have run. The connection string for this database is retrieved in the CustomWebApplicationFactory.cs
file from appsettings.Development.json
Test
value.
To run them:
-
cd into directory:
cd cook-api\CookApi.Tests\
-
Run:
dotnet test