You are here

How to Create a RESTful API With Authentication Using Web API and JWT

Web API is a feature of the ASP.NET framework for simplifying the process of building RESTful HTTP services. The tool’s portability allows it to be used in services that are intended to serve across platforms, device and browsers, and users can create endpoints that are accessible via descriptive URLs and HTTP verbs.

In this tutorial on DeveloperHandbook.com, the author shows followers how to create a RESTful Book Store API that authenticates and authorizes requests, exposes OAuth2 endpoints, and returns data about books and reviews.

The set up occurs in Visual Studio where we open the packages that should have been added to Web API already, with the Entity Framework for data persistence. Followers can add CORS support if they wish, then create the data structure to represent books and reviews. The API Controller is set up to use the Entity Framework’s Seed method to expose data, with a RESTful endpoint that retrieves all of the book data.

The author then handles authentication and authorization using OAuth and JSON Web Tokens (JWT), discussing the enabling of OAuth and formatting of JWT in detail before getting into testing. All code is provided so followers can build the same RESTful API, with instructions to copy the sample code exactly to avoid unpredictable behaviour.
 

Be sure to read the next REST article: How to Create a Simple REST Service Using AWS Lambda

Original Article

Create a RESTful API with authentication using Web API and Jwt

 

Comments