Book Image

Hands-On RESTful Web Services with TypeScript 3

By : Biharck Muniz Araújo
5 (1)
Book Image

Hands-On RESTful Web Services with TypeScript 3

5 (1)
By: Biharck Muniz Araújo

Overview of this book

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.
Table of Contents (20 chapters)
Free Chapter
Section 1: Unraveling API Design
Section 2: Developing RESTful Web Services
Section 3: Enhancing RESTful Web Services
Section 4: Extending the Capabilities of RESTful Web Services

Error messages

We have a well-defined error handler, as we saw in the previous section, so we can now write meaningful error messages that will help you with troubleshooting and make sure that sensitive information is not exposed.

Error messages will depend on the type of application you are coding for. As an example, think about what kind of error message you would like to see to help you solve an issue or understand what is happening.

We will apply some ideas and you can then go further and improve the error messages for the order-api application.

First, we will change the order.ts controller file, as follows:

import { NextFunction, Request, Response } from 'express'
import * as halson from 'halson'
import * as _ from 'lodash'
import { OrderModel } from '../schemas/order'
import { UserModel } from '../schemas/User'
import { formatOutput...