ASP.NET Core 6 Web API with Angular - swagger

I have the following setup: ASP.NET Core 6 Web API with controllers and an Angular 13 frontend.
Some of my controllers will be used by external parties to integrate into my system, while other controllers is specifically for the angular UI. I would like to use NSwag to generate the typescript client for the Angular specific controllers, while I have a separate Swagger json url / specification I can use to give to external parties, that do not show the angular controllers.
IE I need two sets / urls of swagger in the same API project. Can anyone perhaps help on how to configure swagger for this configuration?
Any advise would be greatly appreciated.

So, i had to do the same. I downloaded packages for WebApi project with angular:
Swashbuckle.AspNetCore
Swashbuckle.AspNetCore.SwaggerGen
Swashbuckle.AspNetCore.SwaggerUI
In program.cs:
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
And now access to swagger is from main applicationUrl/swagger, SPA proxy is normally working and redirecting to angular.

Related

Adding a New REST Service Project to an ASP.Net MVC SPA

I have been developing an ASP.Net Core 2.0 SPA web application in Visual Studio 2017 which started life using the new Angular SPA Template (ASP.Net Core SPA Templates). I now need to add reporting to the website and the Telerik Reporting solution I am trying requires a REST Service to function.
Telerik provide a VS 2017 template for their REST Service which I used to add a new .Net 4.6.1 Project to my Solution with its own ReportsController and associated references and code etc. The Telerik REST Service requires the full .Net framework.
My solution builds and runs, I can view my Angular web application, but if I use Postman to send a request to the new ReportsController I just get a 500 server error. I have added a reference in my SPA project to the REST Service project, which I may not require. Should I somehow configure the new REST Service in my SPA project's startup class?
How do I configure my solution such that the new REST Service is launched and listening for requests from my Angular web application please?

Finding View for Swagger UI web page

I have created a new WEB API project integrating Swashbuckle and Swagger UI.
I am able to access Swagger web page via http://localhost:port/swagger/ui/index#/
However, where is the view/index.html/index.cshtml for this page?
I am a newbie to MVC, please help.
The swagger-ui is served by the swashbuckle assembly. The source is not available in your project. You can, however, retrieve the source from github and inject it in swashbuckle as described in the swashbuckle documentation

AngularJS SPA with ASP.NET Web API back-end

I am new to AngularJS and need some advice on how to structure a SPA with Web API for an internal order entry system (SEO not a concern). I would like to set this up in a clean, well-structured fashion for efficient development, debug & deployment.
Here is what I am planning to do:
Not use MVC / razor views (leave all routing and rendering to Angular)
Create two separate Visual Studio (2013) solutions: one just for the AngularJS SPA portion and one for Web API portion (for serving all data to the SPA).
As an alternative, I guess I could use one Visual Studio solution for the full site (both SPA and WebAPI) and then use razor to serve the html files (or figure out how to disable the default MVC plumbing and serve straight HTML instead, to avoid the MVC overhead). Also, would I then have to put both the SPA and the WebAPI in the same project to be able to debug with Visual Studio easily?
Or perhaps there is a better approach?
Advice on best practices / good approaches on this would be appreciated.
We have created a two different projects under the same solution , First one is the empty web application and the next one is a class library .
1) Web application project consists of angular JS and the other client side components .
2) Class library consists of the Web api controllers and the relevant components such as filters and the other details.
We have a bootstrap class in the class library project which bootstraps the webapi and the container for us. Also it makes the testing of Web api easily
public class Bootstrap
{
public void ConfigureRoute(HttpConfiguration httpConfiguration)
{
}
public BootStrapApplication ConfigureContainer()
{
}
}
From the global.asax in the app_start we call the BootStrap application class and the method .
For application structure on angularjs i found the John papa guide efficient https://github.com/johnpapa/angularjs-styleguide
Hope this helps

.NET MVC with WebApi 2 and Durandal - How to disable direct access to files?

I have finished building my first durandal application using .Net MVC and Web Api v2, every thing working fine however I noticed that I can access files directly like
http://localhost:1990/App/views/sessiondetail.html
now I don't want that cuz that is just requesting static pages with no logic or styling.
You will have to override the web servers' default configuration for handling html files in your application, thus tying into to whatever security mechanisms you have in place for request authorization.
This article how explains how to add a handler for all *.html files in your application.

Should swagger UI be a different application

I am currently battling a swagger configuration for my spring MVC RESTful services project. I decided to follow the swagger-spring but I fail to understand if the UI part of swagger should be a totally different project or should it reside in the same context on the container?
The swagger json from my spring mvc based RESTFul services is showing up correctly on a link like: http://<server>:<port>/<context>/api-docs but whenever I put in the swagger UI components in the application(JSP, CSS and JS files), I cannot access the swagger UI, which should look like this.
You need to update index.html that came with swagger-ui. Update below line to your webapp URL.
url: "http://petstore.swagger.wordnik.com/api/api-docs",

Resources