Is it possible to use AngularJS without the REST API?

When I create a simple site with node.js, I am fine using a viewer (like jade) and controllers that provide it with data (like a simple task list). However, if I decided to add AngularJS as a client environment, then it seems to me that I should implement a REST API on the backend to get data from it. Almost all the examples that I see on the Internet using AngularJS have this basic architecture: the client (angular) communicates with the server through the REST API.

Can AngularJS be used without a REST API, and if so, should I do this or should I avoid it? Are there any guidelines / guidelines for using AngularJS without the REST API backend?

+6
source share
4 answers

That's right. Angular can still do a lot on your site, even if you never use the $ http service to talk to your server. You can still use utilities to help manage the DOM.

However, most modern applications need to get data from the server. There are many reasons why you may need to do this. For example, if you have users who need to register, you will need to store their username and password somewhere. This will be somewhere in the database, access to which can only be accessed by your server. Your server will then provide some URLs that you can talk to through the Angular $http .

If you have an application that makes calls on the server, but you want to disable network communication for testing, you can mock answers to the $http call. Angular provides $ httpBackend for this purpose. You can use it to create dummy URLs that pretend to answer your $http calls so that your $http calls don't know that they are not actually talking to the server.

 authRequestHandler = $httpBackend.when('GET', '/auth.py') .respond({userId: 'userX'}, {'A-Token': 'xxx'}); 

Ideal for testing your code without using a REST server during testing.

+5
source

REST, which is short for transferring view state, is basically things or resources instead of actions. Yes AngularJS can be used without a REST API.

+1
source

You can use nodeJS for your calm API and AngularJS as a javascript framework.

Even without the soothing API, AnguarlJS is a very powerful tool for use in the project, although there is full potential (a fully scaled web application) to use it, then you will need the soothing API.

+1
source

use the $ http API for the RESTful API use the $ resource for the RESTful API

0
source

Source: https://habr.com/ru/post/988601/


All Articles