angular-http-api

v0.0.2
An AngularJS HTTP API Service for making paramerterized HTTP calls and getting back useful data structures.
angularjs angular http api xhr json ajax rest restful and 1 more...

Angular HTTP API

Coverage Status Build Status Dependency Status NPM version

The purpose of this library is to provide a very light API for making parameterized URL requests to an API server.

Installation

npm install angular-http-api
# or
bower install angular-http-api

Usage

var app = angular.module('testApp', ['httpApi']);

app.config(function (httpApiProvider) {
  httpApiProvider.setHost('google.com');
  httpApiProvider.preferScheme('https');
});

app.factory('UserService', function (httpApi) {
  return {
    lookupUser: function (email) {
      httpApi.get('/user/:email', {email: email});
    },
    searchUser: function (name) {
      httpApi.get('/user/search', {}, {firstName: name});
    }
  };
});

app.controller('testCtrl', function (UserService) {
  $scope.user;
  $scope.matching = [];

  UserService.lookupUser('[email protected]').then(function (user) {
    $scope.user = user;
  });
  // GET: https://google.com/user/[email protected]

  UserService.searchUser('Peter').then(function (matches) {
    $scope.matching = matches;
  });
  // GET: https://google.com/user/search?firstName=peter
});

License

MIT

npm i angular-http-api

Metadata

  • MIT
  • Whatever
  • Peter M. Elias
  • released 7/9/2014

Downloads

Maintainers