Angular 16 HttpClient & Http Services Tutorial

By Hardik Savani October 20, 2023 Category : Angular

Hi Guys,

Today, angular 16 httpclient get example is our main topic. This example will help you angular 16 http service example. This article will give you a simple example of angular 16 httpclient post example. let’s discuss about angular 16 httpclient service example. Alright, let’s dive into the steps.

Every App must important to send API requests to another server. we can use HTTP client requests and get data and store data information on our server. as especially when you are working with angular, vue, and react applications. you must have to learn how to run HTTP client requests with angular 16.

Here, I will give you a very simple example to get all data using API and storing data using API. we will use JSON placeholder API for testing now. so we don't require creating a new API for it.

So, let's see the below example step on step how to create an HTTP service and how to use it.

Step 1: Create New App

You can easily create your angular app using the below command:

ng new my-new-app

Step 2: Import HttpClientModule

In this step, we need to import HttpClientModule to the app.module.ts file. so let's import it as below:


import { BrowserModule } from '@angular/platform-browser';

import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';

import { HttpClientModule } from '@angular/common/http';


declarations: [



imports: [




providers: [],

bootstrap: [AppComponent]


export class AppModule { }

Step 3: Create Service for API

Here, we need to create a service for HTTP client requests. we will create a service file and write the client HTTP request code. this service will use in our component file. So let's create a service and put the bellow code:

ng g s services/post

Now let's add code as like bellow:


import { Injectable } from '@angular/core';

import { HttpClient } from '@angular/common/http';


providedIn: 'root'


export class PostService {

private url = '';

constructor(private httpClient: HttpClient) { }


return this.httpClient.get(this.url);



Step 4: Use Service to Component

Now we have to use these services for our app component. So let's updated the code as bellow:


import { Component, OnInit } from '@angular/core';

import { PostService } from './services/post.service';


selector: 'app-root',

templateUrl: './app.component.html',

styleUrls: ['./app.component.css']


export class AppComponent implements OnInit {


constructor(private service:PostService) {}

ngOnInit() {


.subscribe(response => {

this.posts = response;




Step 5: Updated View File

Now here, we will update our HTML file. let's put the bellow code:


<h1>Angular 16 HttpClient for Sending Http Request Example -</h1>

<ul class="list-group">


*ngFor="let post of posts"


{{ post.title }}



Run Angular App:

All the required steps have been done, now you have to type the given below command and hit enter to run the Angular app:

ng serve

Now, Go to your web browser, type the given URL and view the app output:


you will see the layout below:

I hope it can help you...