Over a million developers have joined DZone.

Configure a Proxy for Your API Calls With Angular CLI [Video]

Check out this video to learn how to configure the Angular CLI to proxy your API calls to your backend server.

· Web Dev Zone

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

In this video we will learn and demonstrate how to configure the Angular CLI to proxy your API calls to your backend server.

During development, you often end up in the situation where you have your backend API server running at one address (i.e. localhost:3000) while your frontend development server runs on another (i.e. localhost:4200). However, in your Angular 2 services that query the backend API, you don’t obviously want to hard-code the development server’s host, but instead, write your calls as follows:


this.http.get('/api/v1/people')
    .map(res => res.json());


Clearly, this won’t probably work out of the box, because the Angular CLI development server doesn’t answer at /api/v1/people with an API. This is why you need to have some kind of proxy that intercepts such calls and proxies them to your correct backend server API. Let’s learn how to setup such proxy with the Angular CLI.


You didn’t yet have the chance to create an Angular 2 application, but you’re eager to learn it? Watch my introductory video which learns you how to build your first Angular 2 application using the Angular CLI in under one hour.

Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.

Topics:
cli ,proxy ,backend ,api ,angular ,web dev

Published at DZone with permission of Juri Strumpflohner, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}