ASP.Net Core JSON API that is lightweight, no MVC, and cross-platform, no IIS. Create, read, update, and write to your PostgreSQL database out of the box thanks to Npgsql driver and EF Core dependency injection. Includes data migration script that runs on startup and seeds initial data. Get started right away!
I loved the simplicity and portability of spinning up a RESTful app built on NodeJS and Express, only to yearn for the possibility in .NET so that I could write code in C# and leverage tools like Entity Framework, LINQ, Async Await. Hello .NET Core now makes it possible!
Disclaimer
This project borrows heavily from the following repos:
-
RoutingSample blog post here
-
LightweightAPI blog post here
Prerequisites
- Install .NET Core (https://www.microsoft.com/net/core)
- Successfull launches on Windows (Windows7), Mac (OSX 10.11.13), and Linux (CentOS 7.2.1511)
- Install PostgreSQL (https://www.postgresql.org/)
- Successfull CRUD operations on Windows (PostgreSQL 9.4.5) and Mac (PostgreSQL 9.5.2)
- Update lines 22 and 23 in the file Data/ApplicationDbContext.cs with your PostgreSQL user name and password
To run application
- Download repository
- Open command prompt and navigate to repository
- Run command "dotnet restore"
- Please create new issue if you are having trouble downloading dependencies
- Run command "dotnet run"
- Use Postman to send JSON GET, POST, PUT, and DELETE requests.
GET http://localhost:5000/blog
{
"Id": 1,
"ArticleTitle": "How to Dabb",
"ArticleContent": "First tuck you head down..."
},
{
"Id": 2,
"ArticleTitle": "How to Whip",
"ArticleContent": "Rock back and forth..."
},
{
"Id": 3,
"ArticleTitle": "How to Nae Nae",
"ArticleContent": "Add a connecting move..."
},
{
"Id": 4,
"ArticleTitle": "How to Dougie",
"ArticleContent": "Pass your hand through..."
},
{
"Id": 5,
"ArticleTitle": "How to Wop",
"ArticleContent": "Worm your upper body..."
}
GET http://localhost:5000/blog/3
{
"Id": 3,
"ArticleTitle": "How to Nae Nae",
"ArticleContent": "Add a connecting move..."
}
POST http://localhost:5000/blog
{"ArticleTitle":"How to Running Man","ArticleContent":"Lift your right foot and..."}
PUT http://localhost:5000/blog/4
{"ArticleTitle":"How to Moonwalk","ArticleContent":"Place one foot directly..."}
DELETE http://localhost:5000/blog/5