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

34927 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
  • 32,338
  • 34
  • 100
  • 151
663
votes
19 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,839
  • 3
  • 16
  • 10
611
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…
Arash Emami
  • 6,767
  • 3
  • 18
  • 20
494
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
  • 34,522
  • 20
  • 128
  • 188
477
votes
17 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
  • 15,934
  • 15
  • 46
  • 60
451
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
  • 23,306
  • 34
  • 125
  • 265
405
votes
11 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
  • 69,359
  • 26
  • 132
  • 196
402
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
  • 13,594
  • 19
  • 61
  • 91
368
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
  • 57,609
  • 57
  • 177
  • 299
366
votes
7 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
  • 29,899
  • 20
  • 93
  • 155
339
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,193
  • 4
  • 16
  • 25
336
votes
8 answers

Returning binary file from controller in ASP.NET Web API

I'm working on a web service using ASP.NET MVC's new WebAPI that will serve up binary files, mostly .cab and .exe files. The following controller method seems to work, meaning that it returns a file, but it's setting the content type to…
Josh Earl
  • 17,521
  • 15
  • 59
  • 91
328
votes
7 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
  • 19,576
  • 12
  • 48
  • 65
322
votes
9 answers

How to pass json POST data to Web API method as an object?

ASP.NET MVC4 Web API application defines post method to save customer. Customer is passed in json format in POST request body. Customer parameter in post method contains null values for properties. How to fix this so that posted data will passed as…
Andrus
  • 22,189
  • 50
  • 171
  • 330
310
votes
5 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
  • 26,624
  • 8
  • 44
  • 88
1
2 3
99 100