Bing Translate Sample | Source Code
Shows how to call the Microsoft Translator service using the HttpClient class. The Microsoft Translator service API requires an OAuth token, which the application obtains by sending a request to the Azure token server for each request to the translator service. The result from the token server is fed into the request sent to the translation service. Before running this sample, you must obtain an application key from Azure Marketplace and fill in the information in the AccessTokenMessageHandler sample class.
Uses HttpClient to download a map of Redmond, WA from Google Maps API, saves it as a local file, and opens the default image viewer.
Shows how to write a simple Twitter client using HttpClient. The sample uses an HttpMessageHandler to insert OAuth authentication information into the outgoing HttpRequestMessage. The result from Twitter is read using JSON.NET. Before running this sample, you must obtain an application key from Twitter, and fill in the information in the OAuthMessageHandler sample class.
Shows how to retrieve data from the World Bank data site, using JSON.NET to parse the result.
Getting Started with ASP.NET Web API | Source Code
Shows how to create a basic web API that supports HTTP GET requests. Contains the source code for the tutorial Your First ASP.NET Web API.
Shows how to use ASP.NET Web API to build web APIs that support browser clients and can be easily called using jQuery.
Contact Manager | Source Code
This sample uses ASP.NET Web API to build a simple contact manager application. The application consists of a contact manager web API that is used by an ASP.NET MVC application and a Windows Phone application to display and manage a list of contacts.
The AttributeRouting library is a NuGet package provided by Tim McCall and others, which lets you specify routes using attributes directly on your API controllers and actions. This sample illustrates some of these features with ASP.NET Web API.
Azure Blobs File Upload Sample | Source Code
Shows how to use the Azure Blob Storage to store files uploaded to a Web API controller using MIME multipart file upload.
This sample shows how to create a controller protected using a client certificate with SSL. It shows how to get the certificate on the server side and validate it.
Shows how to read and write request and response entities asynchronously using streams. The sample controller has two actions: a PUT action that reads the request entity body asynchronously and stores it in a local file, and a GET action that returns the contents of the local file.
Shows how to set controller-specific configurations. The sample defines an attribute which derives from IControllerConfiguration. When put on a controller, the attribute define specific settings that only apply to that controller.
Custom Assembly Resolver Sample | Source Code
Shows how to modify ASP.NET Web API to support discovery of controllers from a dynamically loaded library assembly. The sample implements a custom IAssembliesResolver which calls the default implementation and then adds the library assembly to the default results.
Shows how to create a custom media type formatter using the BufferedMediaTypeFormatter base class. This base class is intended for formatters which primarily use synchronous read and write operations. In addition to showing the media type formatter, the sample shows how to hook it up by registering it as part of the HttpConfiguration for your application. Note that it is also possible to use the MediaTypeFormatter base class directly, for formatters which primarily use asynchronous read and write operations.
Shows how to customize the parameter binding process, which is the process that determines how information from a request is bound to action parameters. In this sample, the Home controller has four actions:
Shows how to use ASP.NET Web API together with Entity Framework Code First to build an application that helps users find interesting tourist attractions. The application consists of a simple web page that uses AJAX to talk to a Web API, allowing users to locate the tourist attraction closest to a given location. In addition to shipping as part of Visual Studio 2012, Entity Framework is available on Codeplex, allowing you to dive right into the source and participate.
ETW Tracing Sample | Source Code
Shows how to create an ASP.NET Web API ITraceWriter implementation to write to Event Tracing for Windows (ETW).
Shows how to upload files to an ApiController using MIME Multipart File Upload, and how to set up progress notifications with HttpClient using ProgressNotificationHandler. The controller reads the contents of an HTML file upload asynchronously and writes one or more body parts to a local file. The response contains information about the uploaded file (or files).
Shows how to implement HTTP batching within ASP.NET. The batching consists of putting multiple HTTP requests within a single MIME multipart entity body, which is then sent to the server as an HTTP POST. The requests are processed individually, and the responses are put into another MIME multipart entity body, which is returned to the client.
Shows how to use client certificates to authenticate clients in a web-hosted Web API application.
Shows how to wire up HttpMessageHandler instances on both the client (HttpClient) and server (ASP.NET Web API). In the sample, the same handler is used on both the client and server. While it is rare that the exact same handler would run in both places, the object model is the same on client and server side.
JSON Upload Sample | Source Code
Shows how to upload and download JSON to and from an ApiController. The sample uses a minimal ApiController and accesses it using HttpClient.
Shows how to access multiple remote sites asynchronously from within an ApiController action. Each time the action is hit, the requests are performed asynchronously, so that no threads are blocked.
This sample project creates a Nuget package that will install a custom in-memory trace writer into ASP.NET Web API applications.
Shows how to use MongoDB as the persistent store for an ApiController, using a repository pattern.
Namespace Controller Selector Sample | Sourc Code
Shows how to support multiple API controllers with the same name in different namespaces, by providing a custom implementation of the IHttpControllerSelector interface.
NHibernate Queryable Sample | Source Code
Sample shows how to apply OData query options to a custom back-end that is not IQueryable.
OData Composite Key Sample | Source Code
Shows how to create an OData service for an entity with a composite key, and how to provide basic CRUD functionality for it.
OData Paging Sample | Source Code
Shows how to implement server-driven paging using OData.
Shows how to introduce OData queries in ASP.NET Web API using either the
[Queryable] attribute or by using the ODataQueryOptions action parameter which allows the action to manually inspect the query before it is being executed.
This sample illustrates how to create an OData service consisting of three entities and three Web API controllers. The controllers provide various levels of functionality in terms of the OData functionality they expose.
OData Versioning Sample | Source Code
Shows how to create multiple versions of an OData service in the same application, and how to support versioning by route, query string and header.
Shows how to use the PushStreamContent class to write a never-ending response to a client. The controller writes a little bit of data to the client every second until the client disconnects. The client uses HttpClient. To learn how to use it directly in HTML, see Native HTML5 push notifications with ASP.NET Web API and Knockout.js and Real-Time Chart using HTML5 Push Notification (SSE) and ASP.NET Web API.
Relay Sample | Source Code
Shows how to relay requests and responses from a back-end service through a relay controller, asynchronously and without buffering the contents on the server.
Response Body Processor Sample | Source Code
Shows how to copy a response entity (that is, an HTTP response body) to a local file before it is transmitted to the client, and perform additional processing on that file asynchronously. The sample implements an HttpMessageHandler that wraps the response entity with one that both writes itself to the output as normal and to a local file.
Shows how to upload an XDocument to an ApiController using PushStreamContent and HttpClient.
Validation Sample | Source Code
Shows how you can use validation attributes on your models in ASP.NET WebAPI to validate the contents of the HTTP request. Demonstrates how to mark properties as required, how to use both framework-defined and custom validation attributes to annotate your model, and how to return error responses for invalid model states.
Shows how to use ASP.NET Web API within a Web Forms project.
RestBugs is a simple bug tracking application that shows how to use ASP.NET Web API and the new HTTP Client library to create a hypermedia-driven system. The sample includes both client and server implementations, using ASP.NET Web API. The server uses a custom Razor formatter to generate resource representations. The sample also provides a node.js server to illustrate the benefits that come from using a hypermedia design to decouple clients and servers.
These samples are only supported by the latest nightly runtime builds.
Range requests is the ability in HTTP to request a part of a document based on one or more ranges. Clients can use range requests to recover from interrupted data transfers caused by canceled requests or dropped connections. A client can also use them to request a subset of a larger representation, such as a single segment of a very large document for special processing. This sample uses the ByteRangeStreamContent class to support byte range requests.