NestJs: Modern ways to build APIs with Typescript and NestJs
- 11 hours on-demand video
- 4 articles
- 45 downloadable resources
- Full lifetime access
- Access on mobile and TV
- Certificate of Completion
Get your team access to 4,000+ top Udemy courses anytime, anywhere.Try Udemy for Business
- NestJs Fundamentals
- Typescript Decorators, Generics and Classes
- Build RESTFUL APIs with NestJs and MongoDB
- Build RESTFUL APIs with NestJs and MySQL
- Build RestFUL APIs with NestJs and PostgresQL
- Deploy RESTFUL APIs
- Build GraphQL APIs with NestJs
- Add Documentation for your APIS
- Authentication and Authorization using PassportJs
Under the hood, Nest makes use of robust HTTP Server frameworks like Express (the default) and optionally can be configured to use Fastify as well!
In this video, you are going to learn how to create controller in Nest.js. You will learn how to define routes in NestJs
Controllers are responsible for handling incoming requests and returning responses to the client.
In this video, I will teach you how to access the express request object in NestJs.Handlers often need access to the client request details. Nest provides access to the request object of the underlying platform (Express by default). We can access the request object by instructing Nest to inject it by adding the @Req() decorator to the handler's signature.
Earlier, we defined an endpoint to fetch the cats resource (GET route). We'll typically also want to provide an endpoint that creates new records. For this, let's create the POST handler:
A major part of software engineering is building components that not only have well-defined and consistent APIs, but are also reusable. Components that are capable of working on the data of today as well as the data of tomorrow will give you the most flexible capabilities for building up large software systems.
In languages like C# and Java, one of the main tools in the toolbox for creating reusable components is generics, that is, being able to create a component that can work over a variety of types rather than a single one. This allows users to consume these components and use their own types.
In this lecture, I will teach you how to install and setup typescript with Node.js
There are two main ways to get the TypeScript tools:
Via npm (the Node.js package manager)
By installing TypeScript’s Visual Studio plugins
For NPM users:
> npm install -g typescript
You have to create the .ts file and run the tsc and typescript file
The primary reason you create a generic function is because you have some code that meets two criteria:
It's a function or class that will work with a variety of data types
The function or class uses that data type in several places
You have other options: When you have code that works with a variety of data types, you could write one version of the function for each data type, but that's a lot of work and a maintenance nightmare. You could also write one function and have it use the any keyword for its data types, but that would mean abandoning type safety.
Provided that the data types involved are used in several places in your code, a generic function or class is a better solution than your other options: generic functions let you write one version of your code and ensure that the code consistently uses data types (and then, of course, let the developer specify the data type when calling the function/instantiating the class).
In the above example, the type variable T is specified with the function in the angle brackets getArray<T>. The type variable T is also used to specify the type of the arguments and the return value. This means that the data type which will be specified at the time of a function call, will also be the data type of the arguments and of the return value.
You can make a decorator configurable by converting your decorator function into a decorator factory. A decorator factory is a function that returns a decorator function. The factory can have any number of parameters that can be used in the creation of the decorator.
In this video, I will teach you how to get request payload using DTO. A DTO is an object that defines how the data will be sent over the network. We could determine the DTO schema by using TypeScript interfaces, or by simple classes. Interestingly, we recommend using classes here
Middleware is a function which is called before the route handler. Middleware functions have access to the request and response objects, and the next() middleware function in the application’s request-response cycle. The next middleware function is commonly denoted by a variable named next.
While the base (built-in) exception filter can automatically handle many cases for you, you may want full control over the exceptions layer. For example, you may want to add logging or use a different JSON schema based on some dynamic factors. Exception filters are designed for exactly this purpose.
Many-to-one / one-to-many is a relation where A contains multiple instances of B, but B contains only one instance of A. Let's take for example User and Photo entities. User can have multiple photos, but each photo is owned by only one single user.
In this video, I will teach you how to implement many to many relationship. Many-to-many is a relation where A contains multiple instances of B, and B contain multiple instances of A. Let's take for example Question and Category entities. Question can have multiple categories, and each category can have multiple questions.
In this video, You are going to learn how to authenticate user using Passport JWT Strategy in NestJs application. A Passport strategy for authenticating with a JSON Web Token. This module lets you authenticate endpoints using a JSON web token. ... secretOrKey is a string or buffer containing the secret (symmetric) or PEM-encoded public key (asymmetric) for verifying the token's signature.
- Having basic knowledge of TypeScript is recommended, but not required
Nest.js is a progressive Node.js framework for building efficient, reliable and scalable server-side applications. NestJS is a server-side (backend) application framework beautifully crafted to support developers productivity and make their lives happier. Well, it's not only a framework, it's an enabler of entering the world of advanced engineering concepts such as Domain Driven Design, Event Sourcing, Microservices architecture.
I spent a good few years in my career developing large scale apps and it didn’t let me down any single time. It’s well written, having quality as an objective, modular web framework with a good documentation, delivering nice developer experience. Exactly the same way I’d describe Nest.
NestJs is built on the top of Typescript and Express.js. It also combines some elements of Object Oriented Programming and functional programming.
Here comes NestJS, a framework which is fully written in TypeScript (it supports JS too, but types are good), it’s easily testable and brings in all the necessary stuff you always think about but you don’t know what to choose.
NestJS doesn’t try to limit you to a particular way of doing things, it just provides the tooling you need. It doesn’t try to reinvent the wheel, it utilize existing tools you already know. For example, it uses express behind the scenes which makes your app compatible with the majority of express middlewares.
Here are some good reasons why NestJS shines:
Dependency Injection — NestJS provides DI straight out of the box, increasing efficiency, modularity and testability of applications.
Modularisation — NestJS provides a modular structure for organizing code within the same domain boundary into separate modules.
Flexibility — NestJS provides structure, which helps large teams build complex applications and yet comes in as lightweight as possible, so how you want to build is your choice.
Familiar APIs you already know — NestJS is heavily inspired by Angular, it is also quite similar to much established frameworks like Spring and .NET. This provides a shorter learning curve and lower entry threshold for developers.
Community — NestJS is the fastest rising framework, already with 14K stars surpassing HapiJS. Also, with NestJS leveraging on the Angular way of doing things, things can only get better for the community.
In this course, I will teach you the foundations/fundamentals of NestJs. I will teach you how to build RESTFUL APIs step by step. You will also learn how to plan, design and deploy APIs. I have also another separate section of GraphQL.
- Any developer wants to learn how to build backend server side applications with Typescript
- Developers who want to learn how build Restful apis with NestJs, MongoDB and MySQL
- Developers who want to learn how to secure your APIs using JWT
- Developers who want to learn how to deploy NestJs application
- Developers who want to learn how to GraphQL APIs with NestJs