Building RESTful Web Services with .NET Core

Book Description

Building Complete E-commerce/Shopping Cart Application

About This Book
  • Follow best practices and explore techniques such as clustering and caching to achieve a reactive, scalable web service
  • Leverage the .NET Framework to quickly implement RESTful endpoints.
  • Learn to implement a client library for a RESTful web service using ASP.NET Core.
Who This Book Is For

This book is intended for those who want to learn to build RESTful web services with the latest .NET Core Framework. To make best use of the code samples included in the book, you should have a basic knowledge of C# and .NET Core.

What You Will Learn
  • Add basic authentication to your RESTful API
  • Create a Carts Controller and Orders Controller to manage and process Orders
  • Intercept HTTP requests and responses by building your own middleware
  • Test service calls using Postman and Advanced REST Client
  • Secure your data/application using annotations
In Detail

REST is an architectural style that tackles the challenges of building scalable web services. In today's connected world, APIs have taken a central role on the web. APIs provide the fabric through which systems interact, and REST has become synonymous with APIs. The depth, breadth, and ease of use of ASP.NET Core makes it a breeze for developers to work with for building robust web APIs. This book takes you through the design of RESTful web services and leverages the ASP.NET Core framework to implement these services. This book begins by introducing you to the basics of the philosophy behind REST. You'll go through the steps of designing and implementing an enterprise-grade RESTful web service. This book takes a practical approach, that you can apply to your own circumstances. This book brings forth the power of the latest .NET Core release, working with MVC. Later, you will learn about the use of the framework to explore approaches to tackle resilience, security, and scalability concerns. You will explore the steps to improve the performance of your applications. You'll also learn techniques to deal with security in web APIs and discover how to implement unit and integration test strategies. By the end of the book, you will have a complete understanding of Building a client for RESTful web services, along with some scaling techniques.

Style and approach

This book is a step-by-step, hands-on guide to designing and building RESTful web services.

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 If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.

Publisher Resources

Download Example Code

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Building RESTful Web Services with .NET Core
  3. Dedication
  4. Packt Upsell
    1. Why subscribe?
  5. Contributors
    1. About the authors
    2. About the reviewer
    3. Packt is searching for authors like you
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  7. Getting Started
    1. Discussing RESTful services
      1. REST characteristics
      2. Resource-oriented architecture
        1. URI
      3. REST constraints
        1. Client-server architecture
        2. Stateless
        3. Caching
        4. Code on demand (optional)
        5. Uniform interface
          1. More explanation
          2. POST versus PUT explained
        6. Layered system
      4. Advantages and disadvantages of RESTful services
        1. Advantages
        2. Disadvantages
    2. ASP.NET Core and RESTful services
    3. Summary
  8. Building the Initial Framework – Laying the Foundation of the Application
    1. SOAP
      1. SOAP structure
        1. Important points about SOAP
        2. SOAP with HTTP POST
    2. REST
      1. Server and client are independent
      2. Statelessness
    3. Setting up the environment
      1. Running the application
        1. What's cooking here?
        2. Interesting facts
        3. Conclusions
      2. Request and response
        1. HTTP verbs
        2. Postman
        3. GET
        4. Status codes
        5. ASP.NET Core HTTP attributes
        6. POST
        7. PUT
        8. DELETE
    4. SOAP versus REST
    5. Single-page application model
    6. Service-oriented architecture
    7. Summary
  9. User Registration and Administration
    1. Why authentication and limiting requests?
    2. Database design
    3. User registration
      1. Setting up EF with the API
      2. Configuring DbContext
      3. Generating the controller
      4. Calling the API from a page to register the customer
      5. CORS
    4. Adding basic authentication to our REST API
      1. Step 1 – Adding the (authorize) attribute
      2. Step 2 – Designing BasicAuthenticationOptions and BasicAuthenticationHandler
      3. Step 3 – Registering basic authentication at startup
    5. Adding OAuth 2.0 authentication to our service
      1. Step 1 – Designing the Config class
      2. Step 2 – Registering Config at startup
      3. Step 3 – Adding the [Authorize] attribute
      4. Step 4 – Getting the token
      5. Step 5 – Calling the API with the access token
      6. Step 6 – Adding the ProfileService class
    6. Client-based API-consumption architecture
    7. Summary
  10. Item Catalogue, Cart, and Checkout
    1. Implementing controllers
      1. Generating models
      2. Generating controllers
    2. Product listing
    3. Product searching
    4. Adding to cart
    5. Implementing security
      1. Client-side AddToCart function
      2. API calls for AddToCart
        1. POST – api/Carts
        2. PUT – api/Carts/{id}
        3. DELETE – api/Carts/{id}
    6. Placing orders
      1. UI design for placing an order
      2. The client-side PostOrder function
        1. Building order objects to match the model class Orders.cs
        2. Pushing cart items into an order object as an array
        3. Calling POST /api/Orders
      3. PostOrders API POST method
    7. Exposing shipping details
    8. Summary
  11. Integrating External Components and Handling
    1. Understanding the middleware 
      1. Requesting delegates
        1. Use
        2. Run
        3. Map
    2. Adding logging to our API in middleware
      1. Intercepting HTTP requests and responses by building our own middleware
      2. JSON-RPC for RPC communication
        1. Request object
        2. Response object
    3. Summary
  12. Testing RESTful Web Services
    1. Test paradigms
      1. Test coverage and code coverage
      2. Tasks, scenarios, and use cases
      3. Checklist
      4. Bugs and defects
    2. Testing approach
      1. Test pyramid
    3. Types of tests
      1. Testing the ASP.NET Core controller (unit testing)
        1. Getting ready for the tests
        2. Writing unit tests
      2. Stubs and mocking
      3. Security testing
      4. Integration testing
        1. Run tests
      5. Fake objects
        1. Run tests
      6. Testing service calls using Postman, Advanced REST Client, and more
        1. Postman
        2. Advanced Rest Client
      7. User acceptance testing
      8. Performance or load testing
        1. Run tests
    4. Summary
  13. Continuous Integration and Continuous Deployment
    1. Introduction – deployment terminology
      1. The build stage
      2. Continuous integration 
      3. Deployment
      4. Continuous deployment
      5. Continuous delivery
      6. Build and deployment pipeline
      7. Release
      8. Prerequisites for successful RESTful services deployments
    2. The Azure environment
      1. Cloud computing
        1. The benefits of the cloud
        2. Cloud-computing service models
      2. Discussing the Azure environment
        1. Starting with Azure
    3. Publishing/hosting
      1. Project hosting
        1. The dashboard
        2. Code
        3. Work
          1. Adding code to the repository
        4. Test
          1. Creating a test plan
          2. Creating test cases
          3. Running manual tests
        5. Wiki
        6. Build and Release tab
          1. CI versus CD
          2. CI and CD using TFS online
          3. Initiating the CD release process
    4. Summary
  14. Securing RESTful Web Services
    1. OWASP security standards
    2.  Securing RESTful web services
      1. The vulnerable areas of an unsecured web application
        1. Cross-site scripting attacks
        2. SQL injection attacks
          1. What is cooking here?
          2. Fixing SQL injection attacks
        3. Cross-site request forgery
    3. Authentication and authorization in action
      1. Basic authentication, token-based authorization, and other authentications
        1. Basic authentication
          1. The security concerns of basic authentication
        2. Token-based authorization
        3. Other authentication methods
      2. Securing services using annotations
        1. Validations
        2. Securing context
      3. Data encryption and storing sensitive data
        1. Sensitive data
    4. Summary
  15. Scaling RESTful Services (Performance of Web Services)
    1. Clustering
    2. Load balancing
      1. How does it work?
    3. Introduction to scalability
      1. Scaling in (vertical scaling)
      2. Scaling out (horizontal scaling)
      3. Linear scalability
    4. Distributed caching
      1. Caching persisted data (data-tier caching)
        1. First-level caching
        2. Second-level caching
      2. Application caching
        1. CacheCow
        2. Memcached
        3. Azure Redis Cache
      3. Communication (asynchronous)
    5. Summary
  16. Building a Web Client (Consuming Web Services)
    1. Consuming RESTful web services
    2. Building a REST web client
      1. Cooking the web client
        1. Writing code
    3. Implementing a REST web client
    4. Summary
  17. Introduction to Microservices
    1. Overview of microservices
      1. Microservice attributes
    2. Understanding microservice architecture
    3. Communication in microservices
      1. Synchronous messaging
      2. Asynchronous messaging
        1. Message formats
    4. Why we should use microservices
    5. How a microservice architecture works
    6. Advantages of microservices
      1. Prerequisites of a microservice architecture
    7. Scaling
      1. Vertical scaling
      2. Horizontal scaling
    8. DevOps culture
      1. Automation
      2. Testing
      3. Deployment
    9. Microservices ecosystem in ASP.NET Core
      1. Azure Service Fabric – microservice platform
      2. Stateless and Stateful services – a service programming model
      3. Communication – a way to exchange data between services
    10. Summary
  18. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product Information

  • Title: Building RESTful Web Services with .NET Core
  • Author(s): Gaurav Aroraa, Tadit Dash
  • Release date: May 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781788291576