npm

ovh-angular-http

4.0.1-alpha.0 • Public • Published

ovh-angular-http

githubbanner

Maintenance Chat on gitter Build Status

NPM

Simple http provider for OVH API.

Installation

Bower

$ bower install ovh-angular-http --save

NPM

$ npm install ovh-angular-http --save

Get the sources

$ git clone https://github.com/ovh-ux/ovh-angular-http.git
cd ovh-angular-http
$ npm install
$ bower install

Configuration

.config(["OvhHttpProvider", "constants", function (OvhHttpProvider, constants) {
    "use strict";
    OvhHttpProvider.rootPath = constants.swsRootPath; // URL prefix
    OvhHttpProvider.clearCacheVerb = ["POST", "PUT", "DELETE"]; // Auto delete get cache (for this url) if method is in table
    OvhHttpProvider.returnSuccessKey = 'data'; // By default, requeste return response.data
    OvhHttpProvider.returnErrorKey = 'data'; // By default, requeste return error.data
}])

Usage

    // http request
    OvhHttp.["get", "put", "post", "delete"](URL, options); (promise)
 
    // get API schema (option only rootPath)
    OvhHttp.schema(URL, options); (promise)
 
    // get specifically enum of API schema (option only rootPath)
    OvhHttp.models(URL, enumName, options); (promise)
 
    // return window.encodeURIComponent(param);
    OvhHttp.encode(param);

Options

 options = {
    method:           // get post put or delete
    url:              // url of sws or proxypass
    urlParams:        // params of url (replace {*})
    data:             // data of body for POST and PUT
    params:           // params in URL
    cache:            // cache key (String)
    clearCache:       // (String, String[], boolean) clear cache of this url (boolean) or specifique cache (String or String[])
    clearAllCache:    // (String, String[], boolean) clear all cache of this cache (boolean) or specifique cache (String or String[])
    encodeParams:     // Encode params
    encodeUrlParams:  // Encode url params
 
    // Override provider conf
    returnSuccessKey: // (String or empty string) return specific key (first level) (empty for return all)
    returnErrorKey:   // (String or empty string) return specific key (first level) (empty for return all)
    rootPath:         // prefix url (provider conf)
    clearCacheVerb:   // table of [PUT POST DELETE]. remove automatically cache of url if method is in table(provider conf)
 }

Example

    this.getSelected = function (forceRefresh) {
        return OvhHttp.get("hosting/web/{serviceName}", {
            urlParams: {
                serviceName: $routeParams.productId
            },
            clearCache: forceRefresh,
            cache: "hostingCache"
        });
    };
 
    this.flushCdn = function () {
        return OvhHttp.post("proxypass/hosting/web/{serviceName}/request", {
            urlParams: {
                serviceName: $routeParams.productId
            },
            data: {
                action: "FLUSH_CACHE"
            }
            clearAllCache: "hostingCache" // or ["hostingCache"]
        });
    };

You've developed a new cool feature? Fixed an annoying bug? We'd be happy to hear from you!

Have a look in CONTRIBUTING.md

Related links

License

See https://github.com/ovh-ux/ovh-angular-http/blob/master/LICENSE

Readme

Keywords

Package Sidebar

Install

npm i ovh-angular-http

Weekly Downloads

1

Version

4.0.1-alpha.0

License

BSD-3-Clause

Unpacked Size

789 kB

Total Files

8

Last publish

Collaborators

  • ovh-ux-cds