How to consume an JSON REST api (server)?

A Rest api is accessible by any server path that communicates to the server from any client browser in case of angular. Angular provides us http service of Http module. Service have feature to request, error handling, interceptor, Rxjs observables and operators.

We need to Inject http module in the main module.

import { NgModule } from ‘@angular/core’;

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

import { HttpClientModule } from ‘@angular/common/http’;


imports: [




declarations: [



bootstrap: [ AppComponent ]


export class AppModule {}

Then make common communication service using http service

import { Injectable } from ‘@angular/core’;

import { HttpClient } from ‘@angular/common/http’;


export class ConfigService {

constructor(private http: HttpClient) { }


Then make any kind of request get , post , put, delete

GET Request

getResponse(): Observable<HttpResponse<T>> {

return this.http.get<T>(



Software Engineer | Bharat Swabhiman Patanjali Social Activist | Speaker | Motivator | Yoga Trainer