Code Monkey home page Code Monkey logo

hermes's Introduction

Hermes

Build Status

Hermes is an AngularJS service that provides a direct and feature rich wrapper around $http for REST services.

Basic usage

Hermes provides HermesProvider which can be used to create an Hermes service with an alternative configuration(HermesProvider.createService) and provides default configuration and a default service instance.

End points are accessed in hierarchical form as following:

Hermes.element('factory').element('cars').element('ferrari')

The element functions returns an HermesElement which can call all available HTTP methods and chain another element to the hierarchy as well.

To call an HTTP method do as following:

Hermes.element('factory').element('cars').get({
    params: {
        'starting_id': 100
    }
});

All parameters from $http are available, although some may be overridden by Hermes(url and method for example).

Request Hook

Request hooks can be set by using the Hermes.configuration.requestBuilderHooks array. They can be used to extend all request in uniform way. Note that they will be chained and you can declare custom attributes on the request to pass parameters to hooks.

Hermes.configuration.requestBuilderHooks.push(function (request) {
    request.params['session_id'] = AuthenticationService.getSessionId();
    return request;
});

Error Hook

Request hooks can be set by using the Hermes.configuration.responseErrorHooks array. They can be used to notify global errors as session expiration. One of Hermes features is the capability to resend some request after an error as soon as a promise is resolved.

Hermes.configuration.responseErrorHooks.push(function (data, status, headers, request) {
  if (status == 401 || status == 410) {
    var sessionPromise = $q.defer();

    /* Do some stuff like showing a login dialog
       and accept or reject the promise. */
    AuthenticationService.renewSession(function (result) {
      if (result) {
        sessionPromise.resolve();
      }
      else {
        sessionPromise.reject();
      }
    });

    return sessionPromise.promise;
  }
});

hermes's People

Contributors

greenboxal avatar jgabrielfaria avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.