saideepd / contacts-api-dotnet

.Net 6 REST API with CRUD operations using In-Memory & SQL Database with Entity Framework Core

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

contacts-api-dotnet

A Contacts API built with .Net 6 and Entity Framework Core which stores contact information for any person
The API implements CRUD operations
The API stores the data using In-Memory Database as well as SQL Database
The SQL Database operations are performed using Entity Framework Core & EF Migrations

The API is built based on the YouTube video ASP.NET Core Web API CRUD With Entity Framework - Full Course ⭐ [.NET6 API]

Usage

Simply run git clone https://github.com/saideepd/contacts-api-dotnet and dotnet run --project ContactsAPI.

API Definition

Get Contact

Get All Contacts Request

GET /api/Contacts

Get All Contacts Response

200 OK
[
  {
    "id": "eef37882-168a-4e70-9681-19ecda2efe0e",
    "fullName": "John Doe",
    "email": "john.doe@email.com",
    "phone": 1234567890,
    "address": "221B Blecker Street, Old Town, NYC, USA"
  },
  {
    "id": "1cc685ab-5ddc-4fcc-8b30-fea17f555617",
    "fullName": "Jane Doe",
    "email": "jane.doe@email.com",
    "phone": 8989898081,
    "address": "34th Bull Street, Manhattan, NJ, USA"
  }
]

Get Single Contact Request

GET /api/Contact/{{id}}

Get Contact Response

200 OK
[
  {
    "id": "1cc685ab-5ddc-4fcc-8b30-fea17f555617",
    "fullName": "Jane Doe",
    "email": "jane.doe@email.com",
    "phone": 8989898081,
    "address": "34th Bull Street, Manhattan, NJ, USA"
  }
]

Create Contact

Create Contact Request

POST /api/Contacts

Create Contact Response

200 OK
[
  {
    "id": "1cc685ab-5ddc-4fcc-8b30-fea17f555617",
    "fullName": "Jane Doe",
    "email": "jane.doe@email.com",
    "phone": 8989898081,
    "address": "34th Bull Street, Manhattan, NJ, USA"
  }
]

Update Contact

Update Contact Request

PUT /api/Contacts/{{id}}

Update Contact Response

200 OK
[
  {
    "id": "1cc685ab-5ddc-4fcc-8b30-fea17f555617",
    "fullName": "Janet Dane",
    "email": "janet.dane@email.com",
    "phone": 8989898081,
    "address": "221B Baker Street, London, UK"
  }
]

Delete Contact

Delete Contact Request

DELETE /api/Contacts/{{id}}

Delete Contact Response

200 OK
[
  {
    "id": "1cc685ab-5ddc-4fcc-8b30-fea17f555617",
    "fullName": "Janet Dane",
    "email": "janet.dane@email.com",
    "phone": 8989898081,
    "address": "221B Baker Street, London, UK"
  }
]

Unsuccessful Requests

If any of the API does not have matching record present in Database to perform the respective operations, then the API returns 404 Not Found as response

API Requests

GET /api/Contact/{{id}}
PUT /api/Contacts/{{id}}
DELETE /api/Contacts/{{id}}

Unsuccessful Request Response

404 Not Found
{
  "type": "https://tools.ietf.org/html/rfc7231#section-6.5.4",
  "title": "Not Found",
  "status": 404,
  "traceId": "00-049191ed4040ae3b5fcb8cbb09908cc7-d69eb9f86a77c0f0-00"
}

About

.Net 6 REST API with CRUD operations using In-Memory & SQL Database with Entity Framework Core


Languages

Language:C# 100.0%