GithubHelp home page GithubHelp logo

evgomes / supermarket-api Goto Github PK

View Code? Open in Web Editor NEW
476.0 20.0 167.0 214 KB

Simple RESTful API built with ASP.NET Core and .NET 8 to show how to create RESTful services using a decoupled, maintainable architecture.

Home Page: https://medium.com/free-code-camp/an-awesome-guide-on-how-to-build-restful-apis-with-asp-net-core-87b818123e28

License: MIT License

C# 98.26% Dockerfile 1.74%

supermarket-api's Introduction

Supermarket API

All Contributors

Simple RESTful API built with ASP.NET Core and .NET 8 to show how to create RESTful services using a decoupled, maintainable architecture.

Changes list

Many changes were made to the code presented at the tutorial published on Medium and freeCodeCamp, to make the API code cleaner and to add functionalities that developers may find useful.

If you want to download the original code showed on the tutorial, download the 1.0.0 tag.

  • 2.1.0 [February 9, 2024]

    • Updated .NET version to .NET 8.
    • Updated libraries to match the most recent .NET version.
    • Added Docker support.
    • Refactored code to use expression body methods, primary constructors, and new object and collection initialization.
    • Added required constraint to resources.
  • 2.0.0 [July 5, 2023]

    • Updated .NET version to .NET 7.
    • Updated AutoMapper, Entity Framework Core, and Swashbuckle dependencies to match .NET 7.
    • Enabled implicit usings and nullable types.
    • Added global usings and removed implicit namespaces from the source code.
    • Renamed the UnitOfMeasurement enum type to make it follow the official naming convention.
    • Removed CategoryResponse and ProductReponse types to use a generic Response<T> record type instead.
    • Changed API resources to use record types instead of classes, and to initialize values in an immutable way using init.
    • Added configuration to make all API routes lower-case.
    • Refactored services to include logging using the standar .NET logging provider and to make code cleaner.
  • 1.4.0 [November 26, 2021]

    • Updated .NET version to .NET 5 (see #11)
    • Updated AutoMapper, Entity Framework Core, and Swashbuckle dependencies to match .NET 5.
    • Created BaseApiController class to standardize routes and to automatically apply data annotations validation by using the ApiController attribute.
    • Refactored logic to seed database data and to apply entity type configuration for application models.
  • 1.3.0 [December 15, 2019]

    • Updated ASP.NET Core version to 3.1, fixed issues related to InMemoryProvider, updated Swagger (see #5).
    • Fixed paging calculation mistake, updated descriptions, updated "launchSettings.json" to open Swagger on running the application.
  • 1.2.1 [August 11, 2019]

    • Changed BaseResponse to use generics as a way to simplify responses (see #3).
  • 1.2.0 [July 15, 2019]

    • Changed /api/products endpoint to allow pagination (see #1).
  • 1.1.0 [June 18, 2019]

    • Added Swagger documentation through Swashbuckle.
    • Added cache through native IMemoryCache.
    • Changed products listing to allow filtering by category ID, to show how to perform specific queries with EF Core.
    • Changed ModelState validation to use ApiController attribute and InvalidResponseFactory in Startup.
  • 1.0.0 [February 4, 2019]

Frameworks and Libraries

How to Test

First, download and install the .NET Core SDK.

If you have Docker and Visual Studio installed on your machine, you can open the solution file using Visual Studio and run the project using the Docker profile.

If not, open the terminal or command prompt at the API root path (/src/Supermarket.API/) and run the following commands, in sequence:

dotnet restore
dotnet run

Navigate to http://localhost:5000/api/categories to check if the API is working. If you see a HTTPS security error, just add an exception to see the results.

Navigate to http://localhost:5000/swagger to check the API documentation and to test all API endpoints.

API Documentation

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Matt Barry

πŸ’»

hippie

πŸ’»

NoobInTraining

πŸ’»

Ma'hmmoud Kinawy

πŸ’»

Ahsan Raza

πŸ‘€

dundich

πŸ€”

thedon_chris

πŸ›

subhanisyed17

πŸ›

Eric Wilson

πŸ’¬

PhαΊ‘m TuαΊ₯n PhΓ‘t

πŸ€”

miki-nis

πŸ›

This project follows the all-contributors specification. Contributions of any kind welcome!

supermarket-api's People

Contributors

allcontributors[bot] avatar evgomes avatar hippiezhou avatar mahmmoudkinawy avatar mattbarry avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

supermarket-api's Issues

Tutorial needs updating

This is less of an issue for me now but I was just working through your tutorial and noticed there are inconsistencies what's on the tutorial vs the code here makes it difficult when you encounter errors... Obviously this is due to code being refactored and what not but for people new to the language and the model such as myself, this is quite difficult when it comes to debugging.

I must admit, some of my errors were typos or autocorrect issues but this was more difficult than it could have been due to the quoted code differing from what exists here now.

Even the simple typeof(Startup) issue had my Googling the answer only to find that it was here in the code.

dotnet restore doesn't work

Hello,

I'm trying to follow your howto. However, dotnet restore doesn't work. I'm getting the following:

PS E:\Download\Work\git\supermarket-api\src\Supermarket.API> dotnet restore
  Determining projects to restore...
E:\Download\Work\git\supermarket-api\src\Supermarket.API\Supermarket.API.csproj : error NU1100: Unable to resolve 'Auto
Mapper (>= 13.0.1)' for 'net8.0'. [E:\Download\Work\git\supermarket-api\src\Supermarket.API\Supermarket.API.sln]
E:\Download\Work\git\supermarket-api\src\Supermarket.API\Supermarket.API.csproj : error NU1100: Unable to resolve 'Micr
osoft.EntityFrameworkCore.InMemory (>= 8.0.1)' for 'net8.0'. [E:\Download\Work\git\supermarket-api\src\Supermarket.API\
Supermarket.API.sln]
E:\Download\Work\git\supermarket-api\src\Supermarket.API\Supermarket.API.csproj : error NU1100: Unable to resolve 'Micr
osoft.EntityFrameworkCore.Relational (>= 8.0.1)' for 'net8.0'. [E:\Download\Work\git\supermarket-api\src\Supermarket.AP
I\Supermarket.API.sln]
E:\Download\Work\git\supermarket-api\src\Supermarket.API\Supermarket.API.csproj : error NU1100: Unable to resolve 'Micr
osoft.VisualStudio.Azure.Containers.Tools.Targets (>= 1.19.5)' for 'net8.0'. [E:\Download\Work\git\supermarket-api\src\
Supermarket.API\Supermarket.API.sln]
E:\Download\Work\git\supermarket-api\src\Supermarket.API\Supermarket.API.csproj : error NU1100: Unable to resolve 'Swas
hbuckle.AspNetCore (>= 6.5.0)' for 'net8.0'. [E:\Download\Work\git\supermarket-api\src\Supermarket.API\Supermarket.API.
sln]
  Failed to restore E:\Download\Work\git\supermarket-api\src\Supermarket.API\Supermarket.API.csproj (in 70 ms).

A little help?

Automapper issue

Startup.cs(36,22): error CS1061: 'IServiceCollection' does not contain a definition for 'AddAutoMapper' and no accessible extension method 'AddAutoMapper' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)

Resolved by placing using Automapper; at the top of Startup.cs file

See https://stackoverflow.com/questions/42916182/trying-to-add-automapper-to-netcore1-1-not-recognising-services-addautomapper

UnitOfWork not saving data in my db

Hello!!

I made an api using your tutorial
i can post objects into the database. However when i restart the app I loose all data. I follow ur pattern of UnitOfWork. Not sure if my EFCore version matters but im using 3.1.8 and Im using netcore 3.1. Also, i made the base project in netcore 2.2 like u did and then migrate to 3.1. any ideas what could be with the migration from 2.2 to 3.1?

Error adding AddAutoMapper in Startup.cs

I get error trying to add AutoMapper to my Startup.cs file in a dotNET Core project (a simple tutorial):

  1. installed package from VS Code terminal:
    dotnet add package AutoMapper
    (this added:
to my .csproj file). 2. Added line inside ConfigureServices method: services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); 3. added "using" namespace in my Startup.cs file: using AutoMapper;

The error I get is:
'IServiceCollection' does not contain a definition for 'AddAutoMapper' and no accessible extension method 'AddAutoMapper' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)

dotnet --version
= 3.1.402

What am I missing, please?

NET 6

futures NET 6 Minimal API version ?

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.