Questions tagged [asp.net-web-api]

ASP.NET Web API is a framework for building HTTP services for clients like browsers and mobile devices. It is based on the Microsoft .NET Framework and an ideal choice for building RESTful services.

ASP.NET Web API is a framework that makes it easy to build that reach a broad range of clients. These Web-APIs can be consumed by any clients capable of communicating via HTTP (including browsers, mobile clients, desktop applications, and other web applications). It is useful for building ful applications on the Framework.

Web API was created by Microsoft and released on 15th August 2012.

Web API can be hosted:

  • within
  • outside of ASP.NET and IIS - also known as "self-hosted" (i.e. directly inside a Windows service, WPF application or console application)
  • in memory (not accessible via HTTP from outside of the process, but useful for end-to-end testing scenarios or mocking).

As Microsoft had multiple approaches within its technology stack for creating REST services; WCF Web API, ASP.NET MVC controllers returning JsonValue results; this represents a rationalisation and merging of these efforts. The ASP.NET Web API stands separately from WCF and does not deprecate (at this point) the WCF Web HTTP programming model.

Related tags

37671 questions
1220
votes
29 answers

How do I get ASP.NET Web API to return JSON instead of XML using Chrome?

Using the newer ASP.NET Web API, in Chrome I am seeing XML - how can I change it to request JSON so I can view it in the browser? I do believe it is just part of the request headers, am I correct in that?
naspinski
  • 34,020
  • 36
  • 111
  • 167
679
votes
18 answers

Does IMDB provide an API?

I recently found a movie organizer application which fetches its data from the IMDB database. Does IMDB provide an API for this, or any third party APIs available?
tusay
  • 6,999
  • 4
  • 18
  • 10
671
votes
4 answers

Best practice to call ConfigureAwait for all server-side code

When you have server-side code (i.e. some ApiController) and your functions are asynchronous - so they return Task - is it considered best practice that any time you await functions that you call ConfigureAwait(false)? I had read that it…
Aen
  • 7,433
  • 3
  • 20
  • 21
521
votes
18 answers

Pass an array of integers to ASP.NET Web API?

I have an ASP.NET Web API (version 4) REST service where I need to pass an array of integers. Here is my action method: public IEnumerable GetCategories(int[] categoryIds){ // code to retrieve categories from database } And this is the…
Hemanshu Bhojak
  • 16,972
  • 16
  • 49
  • 64
502
votes
11 answers

WCF vs ASP.NET Web API

I've spent a few months trying to grasp the concepts behind WCF and recently I've developed my first WCF service application. I've struggled quite a bit to understand all the settings in the config file. I am not convinced about the environment but…
LeftyX
  • 35,328
  • 21
  • 132
  • 193
489
votes
6 answers

Is there a tag to turn off caching in all browsers?

I read that when you don't have access to the web server's headers you can turn off the cache using: But I also read that this doesn't work in some versions of IE. Are there any set of
leeand00
  • 25,510
  • 39
  • 140
  • 297
458
votes
14 answers

Best practice to return errors in ASP.NET Web API

I have concerns on the way that we returns errors to client. Do we return error immediately by throwing HttpResponseException when we get an error: public void Post(Customer customer) { if (string.IsNullOrEmpty(customer.Name)) { …
cuongle
  • 74,024
  • 28
  • 151
  • 206
414
votes
11 answers

POSTing JsonObject With HttpClient From Web API

I'm trying to POST a JsonObject using HttpClient from Web API. I'm not quite sure how to go about this and can't find much in the way of sample code. Here's what I have so far: var myObject = (dynamic)new JsonObject(); myObject.Data = "some…
Mark
  • 21,067
  • 14
  • 53
  • 71
406
votes
6 answers

How to secure an ASP.NET Web API

I want to build a RESTful web service using ASP.NET Web API that third-party developers will use to access my application's data. I've read quite a lot about OAuth and it seems to be the standard, but finding a good sample with documentation…
Craig Shearer
  • 14,222
  • 19
  • 64
  • 95
401
votes
8 answers

Difference between ApiController and Controller in ASP.NET MVC

I've been playing around with ASP.NET MVC 4 beta and I see two types of controllers now: ApiController and Controller. I'm little confused at what situations I can choose a particular controller. For ex: If I want to return a view then I've to use…
VJAI
  • 32,167
  • 23
  • 102
  • 164
372
votes
9 answers

How to add Web API to an existing ASP.NET MVC 4 Web Application project?

I wish to add an ASP.NET Web API to an ASP.NET MVC 4 Web Application project, developed in Visual Studio 2012. Which steps must I perform to add a functioning Web API to the project? I'm aware that I need a controller deriving from ApiController,…
aknuds1
  • 65,625
  • 67
  • 195
  • 317
361
votes
8 answers

Why should I use IHttpActionResult instead of HttpResponseMessage?

I have been developing with WebApi and have moved on to WebApi2 where Microsoft has introduced a new IHttpActionResult Interface that seems to recommended to be used over returning a HttpResponseMessage. I am confused on the advantages of this new…
Jason Roell
  • 6,679
  • 4
  • 21
  • 28
358
votes
20 answers

Refused to display in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'

I am developing a website that is supposed to be responsive so that people can access it from their phones. The site has got some secured parts that can be logged into using Google, Facebook, ...etc (OAuth). The server backend is developed using…
Ali Hmer
  • 4,841
  • 3
  • 20
  • 13
356
votes
8 answers

Where is HttpContent.ReadAsAsync?

I see in tons of examples on the web using the new HttpClient object (as part of the new Web API) that there should be HttpContent.ReadAsAsync method. However, MSDN doesn't mention this method, nor does IntelliSense find it. Where did it go, and…
David Pfeffer
  • 38,869
  • 30
  • 127
  • 202
350
votes
7 answers

JWT authentication for ASP.NET Web API

I'm trying to support JWT bearer token (JSON Web Token) in my web API application and I'm getting lost. I see support for .NET Core and for OWIN applications. I'm currently hosting my application in IIS. How can I achieve this authentication module…
Amir Popovich
  • 29,350
  • 9
  • 53
  • 99
1
2 3
99 100