Skip to content

Classic and minimal API projects servicing a SPA front-end along with Swagger/OpenAPI interface, and managing cache settings of the front-end assets

License

Notifications You must be signed in to change notification settings

AKlaus/ServingSpaFromKestrel

Repository files navigation

Build

Code samples for "Hosting SPA + .NET API solution" article.

SPA hosted by .NET API with a caching strategy

Example of WebAPI projects (ASP.NET) servicing a SPA front-end along with the API and Swagger/OpenAPI interface, and managing cache settings of the front-end assets.

Route Handler
Root (e.g. /) or /index.html Returns index.html with specified caching headers
Any static file, e.g. styles.css Returns the requested static file with specified caching headers
Any unknown route, e.g. a SPA page or unknown page/resource Returns index.html to let the SPA to show the "404 Not Found"
/swagger/* The Swagger/OpenAPI interface
API end-points, e.g. /api/* Processed by the API controllers/routes

Folder structure

The key elements of the solution:

  • wwwroot – a sample SPA front-end with two routes serviced by the back-end project.
  • ClassicApi – a WebAPI project with classic controllers servicing the front-end from wwwroot.
  • MinimalApi – a WebAPI project built with minimal API servicing the front-end from wwwroot.
  • Configuration – helper methods used by both projects to configure the middleware for Swagger and SPA.

About

Classic and minimal API projects servicing a SPA front-end along with Swagger/OpenAPI interface, and managing cache settings of the front-end assets

Resources

License

Stars

Watchers

Forks