- Hands-On RESTful Web Services with TypeScript 3
- Biharck Muniz Araújo
- 879字
- 2021-07-02 12:19:15
What this book covers
Chapter 1, Introduction to RESTful API Development, explains RESTful concepts in detail to help you to develop and run RESTful services. The main objective is to show comprehensive examples that transfer the concepts to real scenarios and help you to understand the definitions in a straightforward way.
Chapter 2, Principles of Designing RESTful APIs, prepares you for getting familiar with best practices. Having learned how to simplify operations, how to organize endpoints, how to name objects, and coding standardization in the beginning, this chapter will help you to understand the planning part easily.
Chapter 3, Designing RESTful APIs with OpenAPI and Swagger, focuses on core principles for creating web services. Instead of coding from the start, it describes how to design a web service first, then make it ready to code. Also, this chapter describes OpenAPI principles and implementation principles that can help readers to design their web services to support future changes and requirements.
Chapter 4, Setting Up Your Development Environment, covers the development environment—one of the key elements for most developers. Most developers get frustrated with configurations and tooling. You will learn how to set up a Node.js-based web server to serve your web service. You will also learn transpiling routines to transpile your TypeScript code to JavaScript. We will also cover Linters, which define semantic coding standards and check the source code while coding.
Chapter 5, Building Your First API, Hello World, mainly focuses on how to start the app that will serve the web service. The chapter describes file organization and folder structures for a more maintainable and scalable code base. Then, it focuses on how to define routes with a classic Hello World output as a result of a web service call. Finally, it shows the controller logic that will run when a certain endpoint is called.
Chapter 6, Handling Requests and Responses, covers the steps to take after creating the first route, that is, determining which properties you need while handling the requests that you receive, and also creating other routes. With that being said, it is really important to return meaningful responses in order to change/update application states. This chapter also covers methodologies that will be helpful in testing the application, such as not directly using request/response parameters in methods.
Chapter 7, Formatting the APIs – Output, introduces content negotiation, output formats, and the HAL JSON format to explain stateless API conventions. In the Data serialization section, you will learn how to convert resource objects to JSON objects and JSON arrays. Since JSON is standard nowadays, we mainly focus on that format. We also talk about how to expose data as XML.
Chapter 8, Working with Databases and ODMs, addresses a key point—persisting data for every web service. At any given time, a web service should return/serve the same data to simultaneous API calls. This chapter introduces setting up a MongoDB server and connecting it to your API. We will create some simple database wrapper methods that will help our internal logic while not mixing it with an external dependency.
Chapter 9, Securing Your API, discusses authorization techniques and authenticating users by using JWT-based tokens or basic authentication. Moving on, we use tools such as Passport and also look at security best practices. The chapter then describes the importance of serving API with SSL, and finally, it teaches you how to validate data to avoid exposing sensitive information.
Chapter 10, Error Handling and Logging, focuses on how to handle errors, starting with how to catch them and how to describe what an error is and is not. Without meaningful error messages, errors are hard to debug. Error messages should only describe the error itself and should not expose any sensitive data inside the error. This chapter explains how to write understandable error messages with minimum information.
Chapter 11, Creating a CI/CD Pipeline for Your API, covers DevOps—a must for almost every application life cycle. The containerization of an environment, using Continuous Integration services, running tests before deployment, and getting build notifications are the focus of this chapter. You'll learn how to create a pipeline by Dockerizing your environment using Travis CI, Google Cloud Platform, and GitHub.
Chapter 12, Developing RESTful APIs with Microservices, covers microservices—a hot topic nowadays. When you have your own RESTful API, you will start to think about how to run each service independently and how to control them inside their own medium. This chapter starts with a definition of what a microservice is and is not. Then, we continue with the isolation of APIs within an environment so that they can run autonomously. We also explore the possibilities for splitting an existing API into a smaller, more scalable microservice.
Chapter 13, Flexible APIs with GraphQL, looks at GraphQL, a new approach to serving data. Some people even define GraphQL as REST 2.0. We take a look at the differences and similarities between GraphQL and REST. You will learn how to add support for GraphQL to your existing RESTful API. With examples on querying data, and validating and executing a query, readers will learn how to reap the benefits of GraphQL for their RESTful APIs.