forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangular-httpi-tests.ts
More file actions
64 lines (61 loc) · 2.22 KB
/
angular-httpi-tests.ts
File metadata and controls
64 lines (61 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/// <reference path="./angular-httpi.d.ts" />
(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
}
});
}
);
})();