I'm working on a REST API with a Swagger UI. When it comes time to expose the API, should I expose the Swagger UI as well? If so, how would I package it into my application. Currently, I have the UI downloaded from the GitHub and am storing it in a folder alongside my project.
I'm using Go (with the Echo framework) to write the API.
We should not enable swagger in production due to security threats.
In.net core version 6.0 version, we can protect it with the below code in Program.cs.
if(!app.Environment.IsProduction())
{
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My Service");
c.RoutePrefix = string.Empty; // Set Swagger UI at apps root
});
}
Related
I'm currently working on Quarkus with swagger ui and followed a link to test it below link successfully https://quarkus.io/guides/openapi-swaggerui.
but is there any way to implement apache camel route with swagger ui in quarkus? kindly help me.
If you add the camel-quarkus-openapi-java extension to your application, then you can add documentation to your REST DSL routes and have it rendered as an OpenAPI document. There's more information on how to do this here:
https://camel.apache.org/manual/latest/rest-dsl.html
Then you can configure the default URL that the Swagger UI points to.
For example, assuming you configured your Camel OpenAPI documentation to be served at /openapi.yaml, you can configure the Quarkus Swagger UI extension to consume it.
camel.rest.api-context-path = /openapi.yaml
quarkus.swagger-ui.urls.camel = /openapi.yaml
To a working ABPboilerplate I added an additional pair of .Application and .Core modules based on what I see in the working code. Build/run is fine, but when I run the Web.Host /swagger, I do not see my new Dto APIs in the swagger list. What else do I need? Or, what does swagger parse and when/where is the swagger-parser kicked off? I do not see a configuration other than the general swagger configuration in the Startup.cs. Thanks!
EDIT: We are using the ASP.NET-Core MVC/JQuery permeation of the boilerplate.
It's not very clear to me what is the difference between the options below in https://start.spring.io/ select dependencies fields
Web -
Full-stack web development with Tomcat and Spring MVC
Rest Repositories -
Expressing Spring Data repositories over REST via
spring-data-rest-webmvc
The way I see it, Rest Repositories is pure backend dependencies..
I want to create( learn ) a spring project that has an endpoint to specify for a webhook consumption and can send HTTP request to APIs after doing some backend processing
What I understood is (in lame terms), Rest Repositories enable Spring to automatically add "our so-called Controller specific code" & allows developers to skip adding them for simple purposes.
e.g. this page here shows how easy it would be for us to directly query a DB without adding own API & Service layers.
Spring did it all for us. Plus it also added configurations to override them if we want.
Never used spring data rest but it look that it's main purpose is to make rest webservice over a datasource. I think this is limited.
So you should go with a Web full stack.
You can still do REST with it, and if you don't want view, just return json or anything.
I'm currently developing an ASP.NET 5 Web-API application with VS2015 Ultimate Preview. Some things have changed about configuring EF7 on this new platform.
I've already checked the help in this page: https://github.com/aspnet/EntityFramework/wiki but it doesn't show all the step needed to successfully complete a connection with EF7 (it shows only a partial answer)
Can anyone bring a step-by-step tutorial on how would be the correct way to connect to a database (SQL Server) using EF7?. (not using old syntax like in MusicStore sample app but using more recent syntax)
The code should be the same as you linked in the sample app. You register the context in Startup.cs, within ConfigureServices method using the following code:
public void ConfigureServices(IServiceCollection services)
{
// Add EF services to the services container.
services
.AddEntityFramework(Configuration)
.AddSqlServer()
.AddDbContext<MyDbContext>(options =>
{
options.UseSqlServer(Configuration.Get("Data:DefaultConnection:ConnectionString"));
});
}
Then your MyDbContext will be available for dependency injection, and in your controllers you can do
public MyController(MyDbContext context)
{
...
}
That's it
The following tutorials helped me :
Introduction to Web API : Part 2 – Integrating with Entity Framework 5 Code First
Generic Repository Pattern with Entity Framework and Web API
Building an ASP.NET MVC4 Application with EF and WebAPI
Entity Framework Code First and ASP.NET Web API
Getting started with ASP.NET 5 MVC 6 Web API & Entity Framework 7
Stephen Walther has an updated Music Store tutorial. It starts here
I want to use OData in Web Api for few Action methods in a Controller. What is happening is that once i enable OData in Web Api, the error message format is getting changes for all error .
Is there any way to configure Odata only for specific controller/action routes.
Error Message before Enabling OData looks like:
{"Message":"User Name/Password are invalid ."}
Error Message after Enabling OData looks like:
{
"odata.error":{
"message":{
"lang":"en-US","value":"User Name/Password are invalid ."
}
}
}
I would like to configure OData to handle only specific controllers so that rest of the APIs have no impact of OData setting. Your help is appreciated.
One of the big changes we made between RC and RTM is that we've completely removed the EnableOData extension method. We realized that registering OData formatters globally was a bad idea because it impacts controllers regardless of whether they're meant to be OData controllers.
So, in our v1 release for OData and in our current nightly builds, we've added a new base class called ODataController. If you derive from ODataController (or EntitySetController), you will automatically get support for OData just for that controller. It shouldn't affect the rest of your controllers the way it does now. You should also use config.Routes.MapODataRoute instead of EnableOData.
You can install our latest nightly build using these instructions:
http://blogs.msdn.com/b/henrikn/archive/2012/06/01/using-nightly-asp-net-web-stack-nuget-packages-with-vs-2012-rc.aspx
It should be pretty stable at this point.