Coder Social home page Coder Social logo

contosouniversity-backend's Introduction

ContosoUniversity.API

RESTful API using AspNetCore.Identity and OpenID Connect

  • ASP.NET Core 2.0
  • Entity Framework Core 2.0
  • Code First Migration
  • OpenIdConnect.Server
  • AspNetCore.Identity 2.0
  • EntityFrameworkCore.SqlServer
  • Automapper

Referenced Microsoft and chsakell's REST API best practice

Installation

  1. Clone or download this project
  2. Click ContosoUniversity.sln and open with Visual Studio 2017
  3. Navigate to Build - Rebuild Solution
  4. Navigate to Tools - Extensions and Updates..
  5. Click Online located on the left side and search for Open Command Line and install (restart Visual Studio)
  6. Click on ContosoUniversity.API project on the Solution Explorer, and press ALT + SPACE to open up CLI
  7. Run this migration command: dotnet ef migrations add InitialDatabase -c ContosoContext
  8. Run another command which creates database: dotnet ef database update -c ContosoContext
  9. In Startup.cs, uncomment seeder.InitializeData().Wait(); from Configure method
  10. Press F5 to run the project. (Make sure ContosoUniversity.API is set as startup project)

Best Practice

  • Separation of concerns is widely applied so the codes are not tightly coupled. (Ex: repository patterns)
  • Used Automapper to prevent from over-posting attacks
  • Fluent validation is used
  • RESTful HTTP API using JSON as a data format
  • JWT(JSON Web Tokens) based security (Authentication, Authorization & API calls)

Test API

Use Postman or other API testing tools

  • Retrieve all instructors:

    GET http://localhost:51089/api/instructors

  • Access Apis based on a role (Admin or User):

    POST http://localhost:51089/connect/token

    Create Keys & Values in Body tab, x-www-form-urlencoded section using admin account and copy access_token value

    1

ย GET http://localhost:51089/api/admin where it is decorated with [Authorize(Roles = "Admin")] attribute.

Create Key & Value clicking Headers tab. Paste the access_token value in the Value textbox: Bearer eyjhb...

2

contosouniversity-backend's People

Contributors

kkagill avatar

Watchers

 avatar

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.