Require request header for asp.net core webapi - asp.net-core

I’m trying to get some direction as to where I could configure a set of webapi’s to require a set of request headers we’ll need for tracing purposes. We’re required to also generate a OpenAPI spec for these.
I’ve tried the approach here:
Web Api How to add a Header parameter for all API in Swagger
But this only generates the spec and doesn’t enforce the identified headers to be provided.
I did try the approach using the FromHeader attribute at the controller level which did cover both of my requirements but I need to be able to configure these headers using the appsettings configuration.
Is tapping into swagger and writing a custom middleware the only way to achieve what I’m looking for?
Thank you in advanced!

Related

Header propagation with Flurl and DotNetCore

I've really enjoyed using Flurl the last year but have encountered a problem that Im hoping I can solve using Flurl if possible and not resort ripping it out and using IHttpClientFactory and HttpClient from System.Net.Http
I've got a DotNetCore 3.1 API and our client is calling these APIs with custom headers. "x-activityid" as an example. My API calls out to an external API and so I've created a separate Client class where im calling the endpoints on the external API using Flurl.
I need to propagate some of the headers from the requests incomming to my API to the requests I make to the external API that Im calling using Flurl.
Some related links:
Header propagation using ASP.NET Core
Make HTTP requests using IHttpClientFactory in ASP.NET Core
The whole idea of header propagation depends on awareness of some HTTP server context from which to grab the incoming headers, which is why ASP.NET Core can support such a feature directly while Flurl, a stand-alone library that often gets embedded in things like Xamarin apps, cannot.
But all is not lost, because Flurl is really just a wrapper around HttpClient. To get this feature to work without giving up Flurl, just wire up header propagation in ASP.NET Core exactly as prescribed, allow it to inject HttpClient instances into your service classes, then wrap those instances with Flurl inside those classes. Note that you'll need to adapt the pattern of using FlurlClient directly, as opposed to building calls off URL strings, if you're not doing that already.

How to automatically generate a web UI from a REST API

Is there any solution to automatically generate a web UI from a REST API?
I found Swagger codegen but it generates a client for the API, not a UI.
I need a basic UI, allowing directly from the browser to use the different endpoints and display the response prettily. Something like a basic Postman that would be directly integrated into my website.
I don't have constraint about how the generation is done. Can be done once at build time, or at runtime on server side or on client side.
I've heard good things about retool.com, it seems to do what you need.

Generating documentation for a Datasnap RESTful API

I've been looking for a way to include an auto-generated documentation endpoint to an existing Delphi Datasnap RESTful API.
Can it be done? Are there annotations or external tools I can use?
Where would I begin, how would I proceed? If not from within Delphi itself, can I integrate with e.g. Swagger?
It seems somewhat anachronistic to build a RESTful API without offering a documentation endpoint these days...
Any and all information that could help me in the right direction would be greatly appreciated.
Using Swagger, via YAML has just been added to Delphi through EMS, the latest RESTful API development option in Delphi.
https://delphiaball.co.uk/2016/04/22/swagger-yaml-delphi/
Its based on Attributes that are added to the API end points as they are defined and that in turn creates the YAML to import into Swagger.

Protect Swagger Endpoint with Basic Auth

I use Swagger in my web api project:
GlobalConfiguration.Configuration
.EnableSwagger(c =>...
an so on. We also use SwaggerUI. Works like a charm.
For production we don't like the swagger UI to be available and we would like to protect it with basic auth. Afaik there is no such functionality available out of the box. Is there a way to do it with some kind of 'hack' in the web api? Can i register a dedicated filter only for a specific route or something like this?
Thank you for your help
regards
laurin
The web server that you use may support enabling HTTP basic authentication for URL matching certain pattern (e.g. starting with /swagger-ui).

Can we use REST API and custom templates?

I'd like to create a website with authentication using REST framework. Well I'd not like to use it because I didn't understand everything about it, but I have to.
Can I use the REST API and yet have custom templates for administration and simple browsing ?
What I mean is that when I did the REST tutorial (on their website), I didn't see at all where I could put my templates instead of the ones generated by REST. How can I for example use the authentication of REST with my interface, my web template ?
Cannot figure out what do you mean by custom templates ?
Incase you want to begin with REST then you may start with jersey framework. For Security you may use OPenID or the latest OAuth2.0 specs
Here is my tutorial for REST + OAuth2.0
http://restful-fundamentals.blogspot.in/2013/02/rest-and-http.html
http://restful-fundamentals.blogspot.in/2013/04/oauth-20-introducation.html
Google code repo: http://restful-fundamentals.blogspot.in/2013/04/svn-repository-oauth20-spectifications.html