没有合适的资源?快使用搜索试试~ 我知道了~
首页Practical ASP.NET Web API
Practical ASP.NET Web API,基于dotnetfx4.5。 Chapter 1: Building a Basic Web API Chapter 2: Debugging and Tracing Chapter 3: Media-Type Formatting CLR Objects Chapter 4: Customizing Response Chapter 5: Binding an HTTP Request into CLR Objects Chapter 6: Validating Requests Chapter 7: Managing Controller Dependencies Chapter 8: Extending the Pipeline Chapter 9: Hosting ASP.NET Web API Chapter 10: Securing ASP.NET Web API Chapter 11: Consuming ASP.NET Web API Chapter 12: Building a Performant Web API
资源详情
资源评论
资源推荐

v
Contents at a Glance
About the Author ���������������������������������������������������������������������������������������������������������������xiii
About the Technical Reviewer �������������������������������������������������������������������������������������������� xv
Introduction ���������������������������������������������������������������������������������������������������������������������� xvii
Chapter 1: Building a Basic Web API ■ ���������������������������������������������������������������������������������1
Chapter 2: Debugging and Tracing ■ ����������������������������������������������������������������������������������27
Chapter 3: Media-Type Formatting CLR Objects ■ ��������������������������������������������������������������55
Chapter 4: Customizing Response ■ �����������������������������������������������������������������������������������85
Chapter 5: Binding an HTTP Request into CLR Objects ■ ��������������������������������������������������115
Chapter 6: Validating Requests ■ �������������������������������������������������������������������������������������157
Chapter 7: Managing Controller Dependencies ■ �������������������������������������������������������������175
Chapter 8: Extending the Pipeline ■ ���������������������������������������������������������������������������������211
Chapter 9: Hosting ASP�NET Web API ■ �����������������������������������������������������������������������������231
Chapter 10: Securing ASP�NET Web API ■ �������������������������������������������������������������������������255
Chapter 11: Consuming ASP�NET Web API ■ ���������������������������������������������������������������������275
Chapter 12: Building a Performant Web API ■ ������������������������������������������������������������������295
Index ���������������������������������������������������������������������������������������������������������������������������������315
www.it-ebooks.info

xvii
Introduction
“I hear...I forget, I see...and I remember, I do...and I understand”
—Confucius
e Hypertext Transfer Protocol (HTTP) is the application-level protocol that powers the World Wide Web. One
of the greatest characteristics of HTTP is that it nds support in multiple platforms. HTTP is the lowest common
denominator of many platforms and devices. Hence, the primary benet of creating an HTTP-based service is
reachability. A broad range of clients in disparate platforms can consume your HTTP services.
ASP.NET Web API is a framework from Microsoft for building HTTP services. It is not the only possible means for
building HTTP services in the .NET technology stack; there is Windows Communication Foundation (WCF) as well,
but the ASP.NET Web API framework embraces HTTP instead of ghting against it or abstracting it away. ASP.NET
Web API enables you to create HTTP services through the powerful ASP.NET MVC programming model of preferring
convention over conguration, which is familiar to many .NET web developers. Some of the best features from ASP.
NET MVC, such as routing, model binding, and validation, are all part of ASP.NET Web API as well. ASP.NET Web API
also lends itself well to unit testing, in a similar way toASP.NET MVC.
is book, Practical ASP.NET Web API, is a practical guide that will help you master the basics of the great ASP.
NET Web API framework in a hands-on way. It takes a code-centric approach that will help you grasp the concepts by
seeing them in action as you code, run, and debug the projects that you create as you follow the exercises of a chapter.
ough the main focus of the book is the practice, which is the ‘how’ part of ASP.NET Web API framework
development, the ‘what’ and ‘why’ parts are implicitly covered to the extent needed for you to understand and
appreciate the underlying theoretical concepts demonstrated by the practical code, as you work through the various
scenarios. You will see a lot of code, covering all the practical and basic scenarios that are commonly encountered by
developers. e recommended approach that will provide the maximum benet is to follow this book’s exercises in
sequence and code-along. Although it is a bit of work, I recommend you manually type the code instead of copying
and pasting it from the book’s download les into the Visual Studio classes you work on. is will help you grasp what
you are trying to do, as you work through an exercise. However, if having the completed source code by your side will
be of help, you can nd the code for the examples shown in this book on the Apress web site, www.apress.com. A link
can be found on the book’s information page under the Source Code/Downloads tab.
If you are looking for a book to just read through and gain an understanding of the ASP.NET Web API framework
by simply looking at code listings, this is mostly not your book. While you will see lots of code, this is not a recipe book.
ough you will nd the code listings in the book useful and relevant for many of the scenarios you face day-to-day,
the intention of this book is not to provide you ready-made code that you can copy and paste into the code you are
working on in a real-life project and forge ahead. e objective instead is to provide you the hands-on experience
of learning the basics of the ASP.NET Web API framework. In short, this book follows the proverb quoted in the
epigraph—do, and you will understand.
www.it-ebooks.info

■ IntroduCtIon
xviii
What You’ll Learn
e basics of HTTP services and debugging through Fiddler.•
Request binding and validation.•
Response formatting and customization to suit client preferences.•
Managing the controller dependencies and unit testing.•
Hosting and security fundamentals.•
Consuming HTTP services from various clients.•
Building a performant web API.•
How This Book is Organized
Practical ASP.NET Web API is organized into twelve chapters built around hands-on exercises. Each exercise builds on
the previous one and for this reason, I highly recommend not only reading the chapters in order but also following the
exercises within a chapter in the order presented. You’ll nd the following chapters in this book.
Chapter 1: Building a Basic Web API
We start o by understanding the dierences in building HTTP services using Windows Communication Foundation
(WCF) versus ASP.NET Web API at a high level and move on to building our rst service, which exposes an in-memory
collection over HTTP. We then look at overriding the default behavior of the ASP.NET Web API framework in selecting
the action methods based on the HTTP method and nish o the chapter by creating a create-read-update-delete
service that plays by the rules of HTTP.
Chapter 2: Debugging and Tracing
e ability to view HTTP trac, which consists of the request message sent by the client and the response message
sent by ASP.NET Web API in response to the request, and the ability to hand-craft requests and submit the same to
ASP.NET Web API to view the corresponding response are fundamental requirements for building HTTP services.
is chapter covers Fiddler, a great tool for HTTP debugging, and the web browsers’ built-in tools to capture
and inspect the HTTP trac. is chapter also covers the tracing feature that comes with the ASP.NET Web API
framework.
Chapter 3: Media-Type Formatting CLR Objects
is chapter introduces you to the concept of formatting, which is introduced in the ASP.NET Web API framework.
You will understand how the process of content negotiation (conneg) works and learn to override and extend it.
You will create media type mappings through a query string and request header, a custom media type mapping,
and a custom media formatter, and you’ll learn to extend the out-of-box JSON media formatter. Finally, you’ll look
at controlling what and how members of a type get serialized into HTTP response.
www.it-ebooks.info
剩余328页未读,继续阅读














安全验证
文档复制为VIP权益,开通VIP直接复制

评论9