The Tweetbook API is an example ASP.NET Core Web API project implemented with best practices for real world use. Within the project code are comments explaining the rationale behind key design and project structure considerations. Topics covered are listed below and will be continuously updated as new content is added to the project.
The API documentation for this project is generated automatically. As APIs get larger, it becomes harder to maintain synchronization between documentation and program behavior; automation goes a long way to fix this issue so that API consumers always have the latest (accurate!) information available.
The Swashbuckle package has been used to auto-generate API documentation that obeys the Swagger specification. For example setup, see the Startup and MvcInstaller classes.
While installation of services usually occurs in the Startup entrypoint, that does not mean that all the installation logic needs to go in this class. This project separates installers into separate classes based on responsibility, and uses reflection to access these installers via a common interface. See InstallerExtensions for the implementation.
ASP.NET Core has dependency injection baked right into the framework, and we make good use of it in this project. Services are defined with a particular scope at startup, and injected into classes on an as-needed basis. This has immense benefits including, but not limited to, the following:
- Greater decoupling of classes; better separation of responsibilities
- Improved testability of code
- Increased code re-useabilty
A role is a business level representation of a user (ex. super-admin, admin, guest, etc.). We may want to restrict access to parts of the system based on a user's role(s). This can easily be done by using Role-based authorization in ASP.NET Core. Example implementation of Admin and Poster roles in this repo's code can be found here.
- Versioned Endpoints, Requests, and Responses
- Separation of Domain and Contract
- Authentication via JSON Web Tokens
- Easy Integration Testing