1

I have a Web API that is currently being used in java script clients and I would like to use some of the APIs in MVC projects as the data source.

I haven't been able to find information on consuming the Web API from an MVC Class. Maybe I'm just not looking in the right places. Is there a .Net method for doing this?

2 Answers 2

2

If you are using a recent version of .NET, then you should simply use the HttpClient class.

Sign up to request clarification or add additional context in comments.

1 Comment

And if it's not a version that supports HttpClient look at using WebRequest.
1

If you want an easy way to POST and GET from RESTful urls (like Web API) check out ServiceStack.Text

You can do operations like:

var resultString = fullUrl.PostJsonToUrl(args);
MyType results = resultString.FromJson<MyType>();

Where ...

args can be any object (including an anonymous type) and it gets serialized to JSON automatically.

fullUrl is just a string with the url you're posting to / getting from.

MyType is a class with properties that you're deserializing to. It needs to match the JSON spec that you're getting back.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.