Skip to content

Cooking recipes management API developed in .NET C#

Notifications You must be signed in to change notification settings

luz-ojeda/cook-api

Repository files navigation

Cook API

es

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

Features

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

Table of Contents

Getting Started

Prerequisites

If installing with Docker:

Running the API without Docker

  1. Clone the repository:

    git clone https://github.com/luz-ojeda/cook-api.git
    
  2. 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;"
  },
  // ...
}
  1. Apply migrations

    dotnet restore
    dotnet ef database update
  2. Run the API

    dotnet run

Running the API with Docker

  1. Clone the repository:

    git clone https://github.com/luz-ojeda/cook-api.git
    
  2. Create a db folder in root with your PostgreSQL password in a password.txt file inside. A db-password secret is defined in the compose.yaml file, the db service will retrieve the PSQL password from this secret.

  3. 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.

Additional Notes

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

API Documentation

This API is self-documented using Swagger. With the project running, you can access the API documentation by navigating to:

https://localhost:5255/swagger without Docker or https://localhost:8080/swagger with Docker

Postman Collection

There is a Postman collection available, though it is for local testing only. URL variable can be found in the collection scope set to https://localhost:5255, the .NET default url when running with dotnet run

Run In Postman

Testing

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:

  1. cd into directory:

    cd cook-api\CookApi.Tests\
  2. Run:

    dotnet test

About

Cooking recipes management API developed in .NET C#

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published