0%

Book Description

A step-by-step guide that will help you design, develop, scale, and deploy RESTful APIs with TypeScript 3 and Node.js

Key Features

  • Gain in-depth knowledge of OpenAPI and Swagger to build scalable web services
  • Explore a variety of test frameworks and test runners such as Stryker, Mocha, and Chai
  • Create a pipeline by Dockerizing your environment using Travis CI, Google Cloud Platform, and GitHub

Book Description

In the world of web development, leveraging data is the key to developing comprehensive applications, and RESTful APIs help you to achieve this systematically. This book will guide you in designing and developing web services with the power of TypeScript 3 and Node.js. You'll design REST APIs using best practices for request handling, validation, authentication, and authorization. You'll also understand how to enhance the capabilities of your APIs with ODMs, databases, models and views, as well as asynchronous callbacks. This book will guide you in securing your environment by testing your services and initiating test automation with different testing approaches. Furthermore, you'll get to grips with developing secure, testable, and more efficient code, and be able to scale and deploy TypeScript 3 and Node.js-powered RESTful APIs on cloud platforms such as the Google Cloud Platform. Finally, the book will help you explore microservices and give you an overview of what GraphQL can allow you to do.

By the end of this book, you will be able to use RESTful web services to create your APIs for mobile and web apps and other platforms.

What you will learn

  • Explore various methods to plan your services in a scalable way
  • Understand how to handle different request types and the response status code
  • Get to grips with securing web services
  • Delve into error handling and logging your web services for improved debugging
  • Uncover the microservices architecture and GraphQL
  • Create automated CI/CD pipelines for release and deployment strategies

Who this book is for

If you're a developer who has a basic understanding of REST concepts and want to learn how to design and develop RESTful APIs, this book is for you. Prior knowledge of TypeScript will help you make the most out of this book.

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Hands-On RESTful Web Services with TypeScript 3
  3. Dedication
  4. About Packt
    1. Why subscribe?
    2. Packt.com
  5. Foreword
  6. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  7. 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
  8. Section 1: Unraveling API Design
  9. Introduction to RESTful API Development
    1. Technical requirements
    2. What is REST?
    3. REST architectural styles
      1. Uniform interface
        1. Resource-based
        2. The manipulation of resources using representations
        3. Self-descriptive messages
        4. HATEOAS
      2. Stateless
      3. Cacheable
      4. Client-server architecture
      5. A layered system
      6. Code on demand
    4. HTTP methods for RESTful services
    5. Summary
    6. Questions
    7. Further reading
  10. Principles of Designing RESTful APIs
    1. Technical requirements
    2. Organizing API endpoints
      1. Resource-based APIs
      2. Experience-based APIs
      3. Capability-based APIs
    3. Working with large datasets
      1. Pagination
      2. Sorting
      3. Filtering
    4. Naming conventions
    5. Versioning
      1. Including the version in the URL
      2. Versioning in the subdomain
      3. Versioning on media types
      4. Recommendation
    6. HTTP status codes
      1. 2xx – success
      2. 3xx – redirection
      3. 4xx – client error
      4. 5xx – server error
    7. Summary
    8. Questions
    9. Further reading
  11. Designing RESTful APIs with OpenAPI and Swagger
    1. Technical requirements
    2. API-first concepts
    3. The OpenAPI Specification
      1. Format
      2. Document structure
      3. Data types
    4. Design maturity and implementation
      1. Level 0 – The Swamp of POX
      2. Level 1 – Resources
      3. Level 2 – HTTP Verbs
      4. Level 3 – Hypermedia Controls
    5. Swagger tooling
      1. Swagger Editor
      2. Swagger Codegen
      3. The Swagger UI
    6. Summary
    7. Questions
    8. Further reading
  12. Section 2: Developing RESTful Web Services
  13. Setting Up Your Development Environment
    1. Technical requirements
    2. Installing various web servers
      1. Node.js
      2. npm
      3. Testing Node.js and npm
      4. Express.js
        1. Express installation
        2. First app with Express.js
    3. TypeScript installation
    4. Visual Studio Code
    5. Code Linters
      1. TSLint
      2. Prettier
    6. Testing suites
      1. Mocha and Chai
      2. Stryker
    7. Debugging
    8. Building tasks for coding
    9. Summary
    10. Questions
    11. Further reading
  14. Building Your First API
    1. Technical requirements
    2. Serving the app
      1. Initial configurations and file structure
      2. Defining and controlling basic routes
    3. Testing with Postman
    4. Summary
    5. Questions
    6. Further reading
  15. Handling Requests and Responses
    1. Technical requirements
    2. Creating resource URIs
      1. Creating models
      2. Creating tests for the missing routes
      3. Implementing controllers
      4. Configuring the remaining routes 
      5. Running the application
    3. Query strings, data filtering, and pagination
      1. Query strings and data filtering
      2. Pagination
    4. Summary
    5. Questions
    6. Further reading
  16. Formatting the API - Output
    1. Technical requirements
    2. Content negotiation
    3. Data serialization
    4. Hypertext Application Language
    5. Summary
    6. Questions
    7. Further reading
  17. Section 3: Enhancing RESTful Web Services
  18. Working with Databases and ODMs
    1. Technical requirements
    2. Using MongoDB
      1. Installing MongoDB
      2. MongoDB with Docker
        1. Installing Docker 
        2. Running MongoDB on Docker
      3. Robomongo 
    3. Setting up order-api with Mongo
      1. Configuring Mongoose 
      2. Creating the schemas
      3. Changing tests
      4. Changing the controllers
    4. Manual testing
    5. Summary
    6. Questions
    7. Further reading
  19. Securing Your API
    1. Technical requirements
    2. Security overview
      1. Using HTTPS over HTTP
    3. Improving API security
      1. Using bcrypt to encrypt a password
      2. Adding authentication
      3. Email validation
    4. Manual testing
    5. Summary
    6. Questions
    7. Further reading
  20. Error Handling and Logging
    1. Technical requirements
    2. Error handling
      1. Writing custom error handlers
      2. Adding an error handler to order-api
    3. Error messages
    4. Logging
    5. Summary
    6. Questions
    7. Further reading
  21. Creating a CI/CD Pipeline for Your API
    1. Technical requirements
    2. Continuous Integration
      1. Adding the code to GitHub
      2. Continuous Integration with Travis CI
      3. Adding tests to the pipeline
    3. Continuous Deployment
      1. Manual deployment to GCP
      2. Configuring mLab
      3. Automatic deployment to GCP
      4. Scalability
    4. Summary
    5. Questions
    6. Further reading
  22. Section 4: Extending the Capabilities of RESTful Web Services
  23. Developing RESTful APIs with Microservices
    1. Technical requirements
    2. What are microservices?
    3. Breaking down order-api
      1. Creating the databases
      2. Creating the projects on GitHub
      3. GCP projects
      4. Swagger implementation
      5. Create the skeleton for both microservices
        1. The order-ms code
        2. The user-ms code
    4. Summary
    5. Questions
    6. Further reading
  24. Flexible APIs with GraphQL
    1. Technical requirements
    2. Introduction to GraphQL
      1. Configuring GraphQL with the order-ms service
      2. Improving order-ms with order data 
      3. Connecting with MongoDB
    3. Creating a client with Vue.js
    4. Summary
    5. Questions
    6. Further reading
  25. Assessments
    1. Chapter 1 
    2. Chapter 2 
    3. Chapter 3 
    4. Chapter 4
    5. Chapter 5
    6. Chapter 6
    7. Chapter 7
    8. Chapter 8
    9. Chapter 9
    10. Chapter 10
    11. Chapter 11
    12. Chapter 12 
    13. Chapter 13
  26. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think
18.116.239.195