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

Recommended from Medium

Part 3: Full-stack application development with AngularJS 11 and Asp.Net MVC Core 5.0

Optimizing Sausage Sports Club for Nintendo Switch

Solve A Problem Recursively or Iteratively

Angular: Build reactive forms using Formbuilder

Stop Using console.log() In JavaScript

Create React 17 TypeScript With ESLint , WebPack & SCSS

When writing a React Native app using React Navigation, we often run into a particular problem

Set up a Node.js App with ESLint and Prettier

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

ACHARYA ANIL SURYAVANSHI

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

More from Medium

Reactive Forms in Angular

HOW TO BUILD A LOGIN AND SIGN UP PAGE WITH API AUTHENTICATION IN ANGULAR

How to set up Jest in Angular App

How to Add Sentry to your Angular project with Graphql