Posts

Leveraging Dependency Injection in Angular to Simplify HTTP Calls

Image
When developing Angular applications, managing HTTP requests efficiently is a common challenge. To streamline this process, you might create a common class for making API calls, which can then be extended by other components. However, dependency injection (DI) in Angular can introduce complications, particularly when extending classes that require injected services. In this post, we'll walk through a scenario where we have a common class for making HTTP calls and explore how to use Angular's new inject() function to simplify the DI process. Creating a Common Class for HTTP Calls First, let's create a common class, HTTPClass , which will manage our HTTP requests. This class will use Angular's HttpClient service to make GET and POST requests. Instead of using the constructor to inject HttpClient, we'll use the inject() function directly in the class. import { HttpClient } from ...

Enhancing Express.js Requests with TypeScript: Adding User Objects and More

Image
Express JS has been one of the best Node JS framework for creating backend(server side) part of any application. It is fast and easy to learn and implement. It is soo scalable and reliable that it is being used in small and as well as in large application. I loved using it along with typescript too because it enhances the code quality and readability. In addition, you also get the advantage of better code completion and intellisense when using modern text editors like Visual Studio Code. One of the most useful concept of Typescript is “Declaration Merging” . Declaration Merging allows you to merge two or more distinct declaration or types declared with the same name into a single definition. This concept allows you to attach your own custom property onto another Typescript interface type. Lets take a look at Express middleware. The above code is an Express middleware that is used to ensure that a user is authenticated...