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’;

@NgModule({

imports: [

BrowserModule,

HttpClientModule,

],

declarations: [

AppComponent,

],

bootstrap: [ AppComponent ]

})

export class AppModule {}

Then make common communication service using http service

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

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

@Injectable()

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>(

this.configUrl);

}

--

--

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
ACHARYA ANIL SURYAVANSHI

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