We have a Web API project now I have to create a tool where I can test the methods of the Web API. I need to create a tool where if I give the request I need to get the XML response in UI. What approach should I follow?
You can use SwaggerUI as documentation and request testing tool. More information about Swagger can be found at their official site.
There are some helpful guides how to configure SwaggerUI for your application:
1. ASP.NET MVC Web API 2: https://dotnettutorials.net/lesson/how-to-use-swagger-in-web-api
2. ASP.NET Core Web API: https://learn.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle
Use Accept header while sending the request as "application/json" or "application/xml". Add xml formatting to list of formatters if not already done.
Read more on content negotiation here
https://learn.microsoft.com/en-us/aspnet/web-api/overview/formats-and-model-binding/content-negotiation
I am not sure what you mean by saying that you need to get the XML response in UI. If you need to test something manually and actually see the returned response, then Swagger is the most popular and easy-to-use option I would suggest you.
However, if you need to write automated tests, I would highly recommend you to try the MyTested ASP.Net framework. I personally use it in every web project that I do. It is pretty easy to start writing all kind of tests, it has a lot of functionalities within and can be configured for almost every case. The author is a very kind person and a friend of mine that dedicates most of its time on that project and can always relate to your problems (if such exist) and needs to build a better product.
If you are looking to perform integration tests against your APIs, you can use Postman: Postman
Related
(New to Api documentation)
I am somewhat confused with the difference between SwaggerUI and SwaggerHub.
Currently I have a C# Asp.net Web API code and Swashbuckle.AspNetCore is reading the code and the API is being documented on Swagger UI.
I have adopted a code first approach as everything is already coded. However, I would like to have my API documented in SwaggerHub.
I have currently not found any solutions of this online.
Is this possible and how do I go about doing it?
This is extremely easy to accomplish.
Once your document is generated by Swashbuckle, all that's needed for you to do is "push" the documentation to your instance of SwaggerHub. You can do this using one of two tools:
The create or update command from the SwaggerHub CLI: https://github.com/SmartBear/swaggerhub-cli
The POST /apis/{owner}/{api} endpoint from SwaggerHub's registry API : https://app.swaggerhub.com/apis-docs/swagger-hub/registry-api/1.0.62#/APIs/saveDefinition
With both of these tools you can programmatically send documentation from your build environment to SwaggerHub (as well as a lot of other cools things!).
Hey I'm looking for some tutorials on how to consume an external Web API in ASP.NET MVC or if someone could explain briefly on how to go about it,specifically the https://platform.fatsecret.com/api/
You should check out RestSharp . It makes it very easy to consume an external API in your .NET application, since you can control how the API-response (JSON or XML) is deserialized to your model classes.
You can refer to the websites REST API Documentation on everything you need to include in your requests to their server. Here is an example of a method https://platform.fatsecret.com/api/Default.aspx?screen=rapiref&method=food.get
It breaks it down into what is required to be in your request and what you are to expect to see returned.
As for actual code, you have a few options. You can refer to Microsoft Docs in order to learn how to actually craft, send and receive requests to a REST API. The example shown uses the asp.net client Nuget package. It provides an object which allows you to easily create and receive requests.
Personaly, I like to practice with Postman for Chrome first. It allows you to easily create and receive REST data and even has an option to create template code from your request into multiple languages!
I'm looking at working my long-standing API to run on IIS rather than in a desktop app as it is now. Everything on the API is working so I'd rather not change too much if I don't have to. I know about the new Web API template in ASP.NET MVC 4 and I've worked with it, but I found that it didn't give me the control over everything that this particular project needs.
So my question is, is there any way to build an application for IIS that has something like an entry-point where I can just get a web request then use entirely my own code from there? Or do I have to build something that uses the Web API?
Yes, you'll want an ASP.NET handler.
How To Create an ASP.NET HTTP Handler by Using Visual C# .NET
http://support.microsoft.com/kb/308001
You'll need to handle parsing the request and serializing the result yourself. It's probably much better to create a web-api facade in front of your services than trying to do it manually.
How can I pull a data from any a web site through webrequest in c#? e.g price of the product in www.xxx.com
Thanks,
I suggest that you take a look at Html Agility Pack. It provides you with a lot of good functionality for parsing web pages.
For ANY website - good luck. That is near impossible.
Some websites, however provide an api for you to call and then parse the response. Usually this involves calling their web services/methods and passing in parameters either through a query string. Then hopefully the response is clean enough for you to easily manage.
If they have one, they will advertise it usually. Then you can add the web service as a service reference and use that to make your calls.
I am creating a few basic web services using c#, and I am trying to have the web service return back just a normal name=value&name=value without any kind of xml or json format. The legacy system hitting these services is fairly old and doesn't support xml or json. Is doing this possible?
If the legacy service that's targeting this web service is that old, how exactly are you calling the web service from it? It may be easier to create an .aspx page (or even better, .ashx) that parses the request and makes the response simply using Response.Write.
If you update your question/add a comment with the detail about how you're calling the service, I'll update my answer accordingly =)