ASP.NET Web API 2: Building a REST Service from Start to Finish

ASP.NET Web API 2: Building a REST Service from Start to Finish

Jamie Kurtz, Brian Wortman

Language: English

Pages: 280

ISBN: 1484201108

Format: PDF / Kindle (mobi) / ePub


The ASP.NET MVC Framework has always been a good platform on which to implement REST-based services, but the introduction of the ASP.NET Web API Framework raised the bar to a whole new level.

Now in release version 2.1, the Web API Framework has evolved into a powerful and refreshingly usable platform. This concise book provides technical background and guidance that will enable you to best use the ASP.NET Web API 2 Framework to build world-class REST services.

New content in this edition includes:

  • New capabilities in Web API 2 (currently version 2.1).
  • Support for partial updates, or PATCH.
  • API versioning.
  • Support for legacy SOAP-based operations.
  • How to handle non-resource APIs using REST
  • How to best expose relationships between resources
  • JSON Web Tokens, CORS, CSRF

Get ready for authors Jamie Kurtz and Brian Wortman to take you from zero to REST service hero in no time at all. No prior experience with ASP.NET Web API is required; all Web API-related concepts are introduced from basic principles and developed to the point where you can use them in a production system. A good working knowledge of C# and the .NET Framework are the only prerequisites to best benefit from this book.

Digging into WordPress (8th Edition)

Pro ASP.NET MVC 3 Framework

HTML5: Up and Running

WordPress for Web Developers: An Introduction for Web Professionals

Joomla! 3 Beginner's Guide

HTML5: Up and Running

 

 

 

 

 

 

 

 

 

 

 

 

 

on creating, viewing, and updating tasks. Again, a domain that is simple and well understood will allow you to focus on the nondomain concepts we’re concerned about in this book—specifically, REST and the ASP.NET Web API. First and foremost, the caller should be able to create a new task. And it should be able to do so without being required to provide anything more than a subject. Values such as start date, end date, and so on can be updated later if they’re not known at the time the task is

system, let’s explore some these. Data Access There are quite a few options available in .NET when it comes to data access and object persistence on SQL Server. Most of these options fall into one of two categories: using the various SqlClient objects (e.g., SqlConnection, SqlDataAdapter, and SqlCommand) with stored procedures or embedded SQL, or using an Object Relational Mapper (ORM). Sometimes the two approaches are used together, but more often developers choose one or the other. We will be

the task-management service (there are three of them, at different layers in the application) map to the problem domain. Please take care to avoid confusing them with the .NET Framework’s Task class. This same example under the ASP.NET Web API would involve creating a controller instead of a WCF service class. The method for fetching a Task object exists on the controller, but it is no longer defined by a contract, as it is in WCF. The controller might look like this: public class TasksController

EndTransaction(HttpActionExecutedContext filterContext) { if (!CurrentSessionContext.HasBind(_sessionFactory)) return; var session = _sessionFactory.GetCurrentSession(); if (session == null) return; if (!session.Transaction.IsActive) return; if (filterContext.Exception == null) { session.Flush(); session.Transaction.Commit(); } else { session.Transaction.Rollback(); } TransactionHandled = true; } public void CloseSession() { if (!CurrentSessionContext.HasBind(_sessionFactory)) return; var session

following request to activate task #17, which we created at the end of the previous section. Be sure to substitute the actual number of the task you created if it wasn’t 17. Note that we’re providing bhogg’s credentials to ensure that the request is authorized (because he’s a member of the Senior Worker role): Activate Task Request (abbreviated) POST http://localhost:61589/api/v1/tasks/17/activations HTTP/1.1 Authorization: Basic YmhvZ2c6aWdub3JlZA== Activate Task Response (abbreviated) HTTP/1.1

Download sample

Download