You are previewing ServiceStack 4 Cookbook.
O'Reilly logo
ServiceStack 4 Cookbook

Book Description

Over 70 recipes to create web services, build message-based apps, and work with object-relational mapping

In Detail

Building web services is a complex task as every language and framework has its own architecture, which is not easy to analyze. ServiceStack makes it easy to create web services and build applications.

This book covers a wide range of topics from simple development and initial setup using the ServiceStack framework to more advanced concepts such as integration with other popular .NET frameworks. It will show you how to build your services and will also enable you to ensure your web API's quality with step-by-step recipes that show you powerful unit testing and integration testing patterns. You will also learn how to access your SQL database with speed and simplicity using ServiceStack's object-relational mapping framework, OrmLite.

What You Will Learn

  • Quickly create fast, testable, and maintainable web services with ServiceStack

  • Integrate ServiceStack with existing ASP.NET frameworks such as MVC and SignalR

  • Render HTML using Razor and MarkDown with your ServiceStack services

  • Implement unit and integration testing for your web API to enhance quality and compatibility

  • Work with your SQL database of choice using ServiceStack's ORM, OrmLite

  • Leverage the speed of Redis to scale your web API

  • Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

    Table of Contents

    1. ServiceStack 4 Cookbook
      1. Table of Contents
      2. ServiceStack 4 Cookbook
      3. Credits
      4. About the Authors
      5. About the Reviewers
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers, and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Sections
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        5. Conventions
        6. Reader feedback
        7. Customer support
          1. Downloading the example code
          2. Downloading the color images of this book
          3. Errata
          4. Piracy
          5. Questions
      8. 1. Configuration and Routing
        1. Introduction
          1. Why REST?
        2. Up and running with ServiceStack
          1. How to do It...
          2. How it works...
          3. There's more...
        3. Routing using data transfer object attributes
          1. Getting ready
          2. How to do It...
          3. How it works...
          4. There's more...
        4. Isolating web service routes from a web application
          1. Getting ready
          2. How to do It...
          3. How it works...
          4. There's more...
        5. Common ServiceStack plugins
          1. How to do It...
          2. How it works...
        6. Writing a custom audit plugin
          1. How to do It...
          2. How it works...
          3. See also
        7. Adding Routes via the API
          1. How to do It...
          2. How it works…
          3. There's more...
        8. Structuring your project to avoid dependency issues
          1. Getting ready
          2. How to do It
        9. Managing dependencies with Funq and Inversion of Control (IoC)
          1. Getting ready
          2. How to do It…
          3. How it works…
        10. Sharing and accessing configuration and common functionality using Funq IoC
          1. Getting ready...
          2. How to do It...
          3. How it works...
          4. There's more...
      9. 2. Services and Data Transfer Objects
        1. Introduction
        2. Creating a basic create/read/update/delete service
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more…
          5. See also
        3. Splitting HTTP request methods
          1. Getting ready
          2. How to do it…
          3. There's more...
        4. Hosting services from different assemblies
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        5. Utilizing the original HTTP request
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        6. Overriding serialization of request object types
          1. Getting ready
          2. How to do it…
          3. How it works…
        7. Creating a simple admin service
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        8. Intercepting requests and responses using attributes
          1. How to do It…
          2. How it works…
          3. There's more…
        9. Making a basic proxy for existing web services
          1. How to do It…
          2. How it works…
        10. Wrapping multiple existing services and exposing them through ServiceStack
          1. How to do it…
      10. 3. Testing and Logging
        1. Introduction
        2. Unit testing ServiceStack applications
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        3. Integration testing with the ServiceStack C# client
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        4. Functional contract testing ServiceStack services
          1. Getting ready
          2. How to do it…
          3. How it works…
            1. Testing POST
            2. Testing PUT
            3. Testing DELETE
        5. Accessing the request-and-response object with the JsonServiceClient
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        6. Continuous Integration with TeamCity and self-hosted services
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        7. Logging with a choice of frameworks
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        8. Writing a logger to monitor exceptions via e-mail
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
      11. 4. Object Relational Mapping (OrmLite)
        1. Introduction
        2. Modeling your database with types and attributes
          1. Getting ready
          2. How to do it…
          3. How it works…
            1. PrimaryKey attribute
            2. AutoIncrement attribute
            3. References attribute
          4. There's more…
        3. Using and accessing OrmLite
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        4. Using OrmLite filters to create audit functionality
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        5. CRUD and other common operations
          1. Getting ready
          2. How to do it…
          3. How it works…
            1. Creating records
            2. Updating records
            3. Deleting records
          4. There's more…
        6. Utilizing stored procedures using OrmLite
          1. Getting ready
          2. How to do it…
          3. How it works…
            1. OrmLiteSPStatement
            2. Writing our own wrapper
          4. There's more…
        7. Mapping custom queries to POCOs
          1. Getting ready
          2. How to do it…
          3. How it works…
        8. Starting with an existing database with OrmLite and T4 templates
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        9. Working with Entity Framework and ServiceStack
          1. Getting ready
          2. How to do it…
          3. How it works…
      12. 5. HTML and Form Data
        1. Introduction
        2. Getting started with ServiceStack and Razor templates
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        3. Using Markdown for website content
          1. Getting ready
          2. How to do it…
          3. How it works…
        4. Handling file uploads and streaming data from services
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
            1. Testing file uploads
        5. Overriding Razor views or templates using attributes
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        6. Creating and displaying a login and registration page based on authentication
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        7. Submitting a form to a service and handling server-side validation on an HTML client
          1. Getting ready
          2. How to do it…
          3. How it works…
      13. 6. Filters and Validators
        1. Introduction
        2. Creating static validation rules using fluent syntax
          1. How to do it…
          2. How it works…
          3. There's more…
        3. Returning meaningful HTTP error messages
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        4. Adding custom headers via the response filter
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        5. Restricting file uploads by type using filters
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        6. Creating a user-configurable HTTP callback service using a response filter
          1. Getting ready
          2. How to do it…
          3. How it works…
        7. Applying a rate limit to a web service endpoint using request filter
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        8. Restrict user actions by session details using a validator
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        9. Common HTTP status codes
      14. 7. Security and Authentication
        1. Introduction
        2. Getting started with authentication, sessions, registration, and user repositories
          1. Getting ready
          2. How to do it…
          3. How it works…
        3. Getting started with Twitter authentication
          1. Getting ready
          2. How to do it…
          3. How it works…
        4. Getting started with Google authentication

          1. Getting ready
          2. How to do it…
          3. How it works…
        5. Getting started with Facebook authentication
          1. Getting ready
          2. How to do it…
          3. How it works…
        6. Using multiple authentication providers and persisting a user's preferred profile image
          1. Getting ready
          2. How to do it…
          3. How it works…
        7. Handling password resets for credential-based authentication
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        8. Accessing Windows identity information from ServiceStack for an intranet application
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        9. Validating password complexity with a custom registration validator
          1. Getting ready
          2. How to do it…
          3. How it works…
        10. Migrating users from another system by overriding ServiceStack's credential-based authentication
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        11. Writing your own OpenID authentication provider
          1. Getting ready
          2. How to do it…
          3. How it works…
      15. 8. Working with Redis
        1. Introduction
        2. Getting started with ServiceStack.Redis
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        3. Using Redis as a cache with the ServiceStack client
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        4. Using ServiceStack.Redis for publish/subscribe
          1. Getting ready
          2. How to do it…
          3. How it works…
        5. Using the ServiceStack.Redis client to access a Redis list
          1. Getting ready
          2. How to do it…
          3. How it works…
        6. Using Redis hash data structures in ServiceStack
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's More…
        7. Using Redis Set data structures in ServiceStack
          1. Getting ready
          2. How to do it…
          3. How it works…
        8. Using typed data structures with ServiceStack and Redis
          1. Getting ready
          2. How to do it…
          3. How it works…
        9. Scripting Redis with Lua
          1. Getting ready
          2. How to do it…
          3. How it works…
      16. 9. Integrating with Other Technologies
        1. Introduction
        2. Integrating with ServiceStack using the C# client and Native Types
          1. Getting ready
          2. How to do it…
          3. How it works…
        3. Using ServiceStack with WebForms applications
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        4. Using ServiceStack with ASP.NET/MVC applications
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        5. Broadcasting ServiceStack services with SignalR hubs
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        6. Using ServiceStack with MongoDB
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        7. Using ServiceStack with Elasticsearch
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        8. Working with ServiceStack and AngularJS resources
          1. Getting ready
          2. How to do it…
          3. How it works…
      17. A. Getting Started
        1. Creating a ServiceStack solution with Visual Studio and NuGet
        2. Integrating NUnit
      18. B. Testing Locally
        1. Testing external service callbacks locally using Fiddler2 and IIS Express
      19. Index