Skip to content

A dead simple boilerplate to build Restful API using .NET Core.

Notifications You must be signed in to change notification settings

flipboxstudio/boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Boilerplate

This is a bare metal boilerplate to build Restful API using ASP.NET Core.


Library Stack


Quick Start

Running

git clone https://github.com/flipboxstudio/boilerplate.git
cd boilerplate/App
dotnet restore
dotnet ef database update
dotnet run

Testing

git clone https://github.com/flipboxstudio/boilerplate.git
cd boilerplate/App.Tests
dotnet restore
dotnet test

Configuration

AppSettings.Database.Driver

The database driver you want to use for your Application. Valid settings are:

  • Sqlite
  • Mysql
  • SqlServer

AppSettings.Jwt.Key

A secret to encode your JWT.

AppSettings.Jwt.Issuer

The issuer of the JWT. Remember, the application would validate the valid issuer of incoming JWT, so any misconfiguration this config would resulting your token become always invalid. See here.

AppSettings.Jwt.Audience

The valid audience of the JWT. Remember, the application would validate the valid audience of incoming JWT, so any misconfiguration this config would resulting your token become always invalid. See here.

AppSettings.Jwt.Authority

The valid authority of the JWT. Remember, the application would validate the valid authority of incoming JWT, so any misconfiguration this config would resulting your token become always invalid.

AppSettings.Jwt.Expiry

The timespan of JWT in minutes. After n minutes of issuing the JWT, that token would be blacklisted. Default value is 60, means after one hour the token would become expired. See here.

ConnectionStrings.{Driver}Connection

If you configure your database using Sqlite driver, the used connection string would be ConnectionStrings.SqliteConnection. If you configure your database using Mysql driver, the used connection string would be ConnectionStrings.MysqlConnection. And if you configure your database using SqlServer driver, the used connection string would be ConnectionStrings.SqlServerConnection.


Available API

User Registration

Example Request

POST /api/v1/auth/register HTTP/1.1
Host: localhost:1822
Content-Type: application/json

{
  "email":"[email protected]",
  "password":"P4ssw0rd!"
}

Example Response

{
    "message": "Registration success.",
    "status": 806,
    "data": {
        "token": "JWT_TOKEN",
        "user": {
            "id": "bde2fada-39fe-42ab-a0ee-29ce040bc8e9",
            "user_name": "[email protected]",
            "normalized_user_name": "[email protected]",
            "email": "[email protected]",
            "normalized_email": "[email protected]",
            "email_confirmed": false,
            "security_stamp": "29901b62-2a31-4718-a35e-a8cea3d3e93a",
            "concurrency_stamp": "0d027542-a523-4076-b939-e52ccc6f1221",
            "phone_number_confirmed": false,
            "two_factor_enabled": false,
            "lockout_enabled": true,
            "access_failed_count": 0
        }
    }
}

User Authentication

Example Request

POST /api/v1/auth/login HTTP/1.1
Host: localhost:1822
Content-Type: application/json

{
  "email":"[email protected]",
  "password":"P4ssw0rd!"
}

Example Response

{
    "message": "Authentication success.",
    "status": 801,
    "data": {
        "token": "JWT_TOKEN"
    }
}

Check Current User

Example Request

GET /api/v1/auth/authorize HTTP/1.1
Host: localhost:1822
Authorization: Bearer JWT_TOKEN

Example Response

{
    "message": "Authorized.",
    "status": 808,
    "data": {
        "user": {
            "id": "bde2fada-39fe-42ab-a0ee-29ce040bc8e9",
            "user_name": "[email protected]",
            "normalized_user_name": "[email protected]",
            "email": "[email protected]",
            "normalized_email": "[email protected]",
            "email_confirmed": false,
            "security_stamp": "29901b62-2a31-4718-a35e-a8cea3d3e93a",
            "concurrency_stamp": "0d027542-a523-4076-b939-e52ccc6f1221",
            "phone_number_confirmed": false,
            "two_factor_enabled": false,
            "lockout_enabled": true,
            "access_failed_count": 0
        }
    }
}

LICENSE

Copyright (c) 2017 Flipbox Studio

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Written with ❤️ by Flipbox at Jakarta.

About

A dead simple boilerplate to build Restful API using .NET Core.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published