Asked by:
.net and Swagger API

Question
-
User-301279762 posted
I am looking to pass paramaters to query a DB via the swagger API.
I want to return the results of my query in an asp.net page.
Does anyone have any experience of querying using the Swagger API?
Thanks.
Tuesday, July 28, 2020 3:45 PM
All replies
-
User475983607 posted
Swagger is a tool for documenting Web API services. Do you have a Web API service and Swagger currently up and running? Are you trying to generate client code that calls Web API?
Tuesday, July 28, 2020 4:20 PM -
User-301279762 posted
Yes a third party provider has a Web API and Swagger already up and running.
I want to pass parameters in a query to their repository and to return the record which I request from their repository.
What would I need to use to do this?
Thanks.
Tuesday, July 28, 2020 10:10 PM -
User475983607 posted
DotNetNewbie2020
Yes a third party provider has a Web API and Swagger already up and running.
I want to pass parameters in a query to their repository and to return the record which I request from their repository.
What would I need to use to do this?
That's the whole purpose of the Swagger UI. The UI shows developers everything needed to make a REST request. The best I can do is provide a tutorial that illustrates how to make HTTP requests to Web API from C#.
https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/console-webapiclient
I recommend creating a demo. Build an basic Web API application, add swagger to the API, then create another project MVC or a Console that makes requests to the API app. The tutorials above have the API and Console bits. I think that adding swagger and playing around will help with your understanding of the swagger tool.
Tuesday, July 28, 2020 10:53 PM -
User-301279762 posted
Thanks for the reply.
Would this kind of development be regarded as quite advanced development in .NET?
Wednesday, July 29, 2020 8:52 AM -
User475983607 posted
Would this kind of development be regarded as quite advanced development in .NET?Consuming services is very common in web development. The concept has been a feature since the 90s. REST is simply the latest (really gRPC) .NET service framework. Swagger is a tool for documenting REST (Web API) services. Documenting means illustrating how to call the service and the data interfaces (Input/Output) to expect.
I would not call it advanced. I'd call it necessary for web developers. If you are new then take the time to learn Web API. Build a client that calls Web API. Then add swagger to the Web API app. At that point you'll understand the problem Swagger solves.
Wednesday, July 29, 2020 11:29 AM -
User753101303 posted
Hi,
The purpose of Swagger is to document how you can use this 3rd party web API. Then you can code actual API calls "by hand" using for example https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient?view=netcore-3.1 or you could try a tool such as https://github.com/RicoSuter/NSwag/wiki/NSwagStudio to generate a client from the API documentation.
Edit: for example you should see something such as https://docs.microsoft.com/en-us/aspnet/core/tutorials/web-api-help-pages-using-swagger?view=aspnetcore-3.1#swagger-ui that shows which HTTP requests you could send and which response you'll get as a response.
Wednesday, July 29, 2020 11:43 AM