Live example running on Heroku right now. Check out Heroku_Deploy branch for more details
A lightweight and cross platform ASP.Net Core JSON API. CRUD 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!
Data security using tokens,JWT, and ASP.Net Core Identity, claims based authentication.
Disclaimer
This project borrows heavily from the following repos:
Prerequisites
- Install .NET Core (https://www.microsoft.com/net/core)
- Install PostgreSQL (https://www.postgresql.org/)
- Add an appsettings.json file to /src/BareMetalApi, which will define your db connection string.
{
"ConnectionStrings": {
"DefaultConnection": "User ID=postgres;Password=password;Host=localhost;Port=5432;Database=Blog;Pooling=true;"
}
}
To run application
- Download repository
- Open command prompt and navigate to /src/BareMetalApi
- Run command "dotnet restore"
- Please create new issue if you are having trouble downloading dependencies
- Run command "dotnet run"
- App will compile then run, wait for message
Application started. Press Ctrl+C to shut down.
- App will compile then run, wait for message
- First Register a User: Use Postman to send a POST request in order to register your first user.
POST http://localhost:5000/blog/account/register
{"Email" : "YourName@ok.com", "PasswordHash" : "Abc!"}
- Get Security Token: Use Postman to login your user.
POST http://localhost:5000/blog/account/login
Body
x-www-form-urlencoded
Email
YourName@ok.com
Password
Abc123!
- Use your security tokens to send JSON GET, POST, PUT, and DELETE requests.
GET http://localhost:5000/blog/blogarticle
Headers
Authorization
Bearer eyJhbGc...FULL TOKEN...RrXfOA
{
"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/blogarticle/3
Headers
Authorization
Bearer eyJhbGc...FULL TOKEN...RrXfOA
{
"Id": 3,
"ArticleTitle": "How to Nae Nae",
"ArticleContent": "Add a connecting move..."
}
POST http://localhost:5000/blog/blogarticle
{"ArticleTitle":"How to Running Man","ArticleContent":"Lift your right foot and..."}
PUT http://localhost:5000/blog/blogarticle/4
{"ArticleTitle":"How to Moonwalk","ArticleContent":"Place one foot directly..."}
DELETE http://localhost:5000/blog/blogarticle/5