diff --git a/angular-httpi/httpi-tests.ts b/angular-httpi/httpi-tests.ts new file mode 100644 index 000000000..2d8ffa84f --- /dev/null +++ b/angular-httpi/httpi-tests.ts @@ -0,0 +1,64 @@ +/// + +(function() { + 'use strict'; + var app = angular.module("Demo", ["httpi"]); + // -------------------------------------------------- // + // -------------------------------------------------- // + // I control the main demo. + app.controller( + "DemoController", + function($scope: ng.IScope, httpi: Httpi.HttpiFactory) { + + console.warn("None of the API endpoints exist - they will all throw 404."); + // NOTE: The (.|.) notation will be stripped out automatically; it's only + // here to improve readability of the "happy paths" for interpolation + // labels. The following urls are pre-processed to be identical: + // -- + // api/friends/( :listCommand | :id/:itemCommand ) + // api/friends/:listCommand:id/:itemCommand + var resource = httpi.resource("api/friends/( :listCommand | :id/:itemCommand )"); + // Clear list of friends - matching listCommand. + resource.post({ + data: { + listCommand: "reset" + } + }); + // Create a new friend - no matching URL parameters. + resource.post({ + data: { + name: "Tricia" + } + }); + // Get a given friend - ID matching. + resource.get({ + data: { + id: 4 + } + }); + // Make best friend - ID, itemCommand matching. + resource.post({ + data: { + id: 4, + itemCommand: "make-best-friend" + } + }); + // Get gets friends - no matching URL parameters. + resource.get({ + params: { + limit: "besties" + } + }); + // Get a friend as a JSONP request. + // -- + // NOTE: The "resource" will auto-inject the "JSON_CALLBACK" marker that + // AngularJS will automatically replace with an internal callback name. + resource.jsonp({ + data: { + id: 43 + } + }); + } + ); + +})(); \ No newline at end of file diff --git a/angular-httpi/httpi.d.ts b/angular-httpi/httpi.d.ts new file mode 100644 index 000000000..eb4a16106 --- /dev/null +++ b/angular-httpi/httpi.d.ts @@ -0,0 +1,42 @@ +// Type definitions for angular-httpi +// Project: https://github.com/bennadel/httpi +// Definitions by: Andrew Camilleri +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module Httpi { + export interface HttpiPayload extends ng.IRequestShortcutConfig { + method?: string; + url?: string; + params?: {}; + data?: {}; + keepTrailingSlash?: boolean; + } + + export interface HttpiFactory { + + (config: HttpiPayload): ng.IHttpPromise<{}>; + + resource(url: string): HttpiResource; + } + + export class HttpiResource { + + constructor(http: ng.IHttpService, url: string); + + delete(config: HttpiPayload): ng.IHttpPromise; + + get(config: HttpiPayload): ng.IHttpPromise; + + head(config: HttpiPayload): ng.IHttpPromise; + + jsonp(config: HttpiPayload): ng.IHttpPromise; + + post(config: HttpiPayload): ng.IHttpPromise; + + put(config: HttpiPayload): ng.IHttpPromise; + + setKeepTrailingSlash(newKeepTrailingSlash: boolean): HttpiResource; + } +} \ No newline at end of file