Search Posts

Category: rest

What is ‘API first architecture’ in modern web application

I try to understand the API first architecture to apply on web application, and found some info here, Advantages of a separate REST backend API? Below I attach an example for better answer of the questions. I start using Angular.js for front-end. Node.js, Express.js for server. folder structure |– server.js |– app |– models |– views |– index.html |– about.html |– contact.html |– controllers |– app.js |– node-modules app folder is a MVC structure for […]

How to pass basic authentication in rest service in AngularJS?

I have a REST web service that requires a basic authentication to consume its data. I am consuming it in AngularJS. The way I am doing it is as follows: $http.get(‘http://localhost:9200/persons/_search?_source=Gender’, { headers: { withCredentials: true, headers:{ ‘Authorization’: ‘Basic ‘ + btoa(“admin” + “:” + “admin”)} } }). then(function(response) { ctrl.json =; }); }]); But the error that I am having in the console is: Request header field headers is not allowed by Access-Control-Allow-Headers […]

AngularJS promise catch 401

I am using a very basic angularJS code for a user login like this: […] this.login = function(email, password) { promise = $‘/login’, { ’email’: email, ‘password’: password }); promise.then(function(response){ console.log(“success”); }).catch(function(response){ console.log(“catch”); }).finally(function(response){ console.log(“finally”); }); return promise; }; […] When the REST API generates an response with code 200, then the client console will log success finally and the user is logged in. When the server generates a response with a 403 or 500 […]

AngularJS – HTTP GET request with status code 302

I am building a RESTful API using AngularJS, and i got stuck. I am trying to send a GET request which will fetch me a User with given username. Here is the code: var loginModule = angular.module(‘login-module’, []); loginModule .factory(‘loginService’,[‘$http’,’$rootScope’, function($http){ var factoryMethods = {}; factoryMethods.login = function(username){ return $http.get(‘http://localhost:8080/WebProjekat/webapi/users/’+username); } factoryMethods.setLoggedUser = function(user){ $rootScope.loggedUser = user; } return factoryMethods; }]) .controller(‘loginController’, [‘$scope’, ‘$http’,’loginService’, function ($scope, $http, loginService){ $scope.username = ”; $scope.password = ”; $scope.user […]

Django restful api can not get file content

I use Django restful api + angularjs . Now ,I append to use angularjs upload file to server by Django restful api On the web front-end ,The Html is: <input type=”file” data-upload-file id=”uploadInputFile”> The angularjs’s code is : omapp.directive(“uploadFile”,function(httpPostFactory){ return { restrict:”A”, scope:true, link:function(scope,element,attr){ element.bind(‘change’,function(){ var formData = new FormData(); formData.append(‘file’, element[0].files[0]); console.log(formData.get(‘file’)) httpPostFactory(‘/api/uploadfile/’,formData.get(‘file’),function (callback) { console.log(callback); }) }) } }; }); omapp.factory(‘httpPostFactory’, function ($http,$cookies) { return function (file, data, callback) { var req = […]

RESTFUL App in symfony 3

I am still quite confused about REST API, Angular and so on. I would like to build simple web app which allows users to book events and I would like to do it in Symfony 3 + Angular. In future, I could make it work on mobile phones as well. The reason I want to do it is to learn symphony 3, REST API and Angular better and to increase chance I will get hired. […]