I'm new to ASP.NET MVC and have an existing API which returns JSON. This API exists on another server and I need to make a server-to-server call to API and bind the resultant data to a Model so that it can be used within other parts of this web app I'm making.
I tried searching for this and it seems like it exists but I can't find the basic documentation for it or how to implement it.
I could make each component (make HTTP request, parse the JSON, set a model to use the data), but I'd hate to re-invent the wheel (and probably do it poorly) if this is something that is already in the library.
Example of the API call:
http://example.info/feeds/feed.aspx?alt=json-in-script
response:
{
"version": "1.0",
"encoding": "UTF-8",
"feed": {
"updated": {
"$t": "2014-07-08T13:58:21-05:00"
},
"id": {
"$t": "http://example.info/feeds/feed.aspx"
},
"title": {
"type": "text",
"$t": "Example Calendar of Events"
},
"link": [
{
"rel": "alternate",
"type": "text/html",
"href": "http://feed.example.edu/search/"
},
{
"rel": "alternate",
"type": "application/json",
"title": "JSON",
"href": "http://example.info/feeds/feed.aspx?alt=json"
},
{
"rel": "alternate",
"type": "text/calendar",
"title": "iCal",
"href": "http://example.info/feeds/feed.aspx?alt=ical"
},
{
"rel": "self",
"type": "application/atom+xml",
"title": "ATOM Feed",
"href": "http://example.info/feeds/feed.aspx"
}
],
"author": [
{
"name": {
"$t": "Example!!"
},
"email": {
"$t": "[email protected]"
}
}
],
"gd$where": [
{
"valueString": "Chicago, IL, US"
}
],
"gCal$timezone": {
"value": "America/Chicago"
},
"entry": [
{
"category": [
{
"scheme": "http://schemas.google.com/g/2005#kind",
"term": "http://schemas.google.com/g/2005#event"
},
{
"term": "Current Students"
},
{
"term": "Faculty"
},
{
"term": "Staff"
}
],
"published": {
"$t": "2012-03-06T20:57:24+00:00"
},
"updated": {
"$t": "2012-03-06T20:57:24+00:00"
},
"id": {
"$t": "http://example.info/feed/?eventid=74289"
},
"gCal$uid": {
"value": "[email protected]"
},
"title": {
"type": "text",
"$t": "Last Day of Sessions 1 & 4 Classes"
},
"content": {
"type": "html",
"$t": "<p>Session 1 & 4 period ends today.</p>"
},
"summary": {
"type": "text",
"$t": "Session 1 & 4 period ends today."
},
"author": [
{
"name": {
"$t": "Office"
},
"email": {
"$t": "[email protected]"
}
}
],
"gd$who": [
{
"rel": "http://schemas.google.com/g/2005#event.organizer",
"valueString": "Registrar, Office of the"
},
{
"rel": "http://schemas.google.com/g/2005#event.attendee",
"valueString": "Current Students"
},
{
"rel": "http://schemas.google.com/g/2005#event.attendee",
"valueString": "Faculty"
},
{
"rel": "http://schemas.google.com/g/2005#event.attendee",
"valueString": "Staff"
}
],
"gd$organization": [
{
"label": "Campus",
"primary": "true",
"gd$orgName": {
"$t": "Chicago"
}
}
],
"gd": {
"value": "http://schemas.google.com/g/2005#event.opaque"
},
"link": [
{
"rel": "alternate",
"type": "text/html",
"href": "http://feed.example.edu/viewevent.aspx?eventid=74289&occurrenceid=127924"
}
],
"gCal$sequence": {
"value": "0"
},
"gd$when": [
{
"startTime": "2014-07-30",
"endTime": "2014-07-31"
}
],
"gd$where": [
{
"valueString": "Classes administered by the Chicago Campus"
}
]
},
...
]
}
}
Edit:
I just now found this article on Calling a Web API From a .NET Client, which is in-line with what I'm trying to ask with this question, but I need to know how to do this in an ASP.NET MVC context, not a console application.
See Question&Answers more detail:
os