-
Notifications
You must be signed in to change notification settings - Fork 12
Usage of Proxy Client
Work in progress - Will be updated
Since typescript 2.1 an async await shim is supported. These settings in tsconfig.json worked for me so far:
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"lib": ["dom", "es2015.promise", "es5"]
}To get odata entries just create a new instance of your proxy class and call the get function. This will return all entries in your entity set. You can call this using async await or the then callback.
Example using await:
let comm = new MovieProxy("http://localhost:2200/moviedb", "Testproxy");
let result = await comm.Addresses.Get();Example using .then():
let comm = new MovieProxy("http://localhost:2200/moviedb", "Testproxy");
let result = comm.Addresses.Get().then((val) => {
// Your callback here
});This works for all methods. It will result in this odata request:
GET http://localhost:2200/moviedb/Addresses
To get a single entry just use the .Get(<yourkey>) method overload.
let comm = new MovieProxy("http://localhost:2200/moviedb", "Testproxy");
let result = await comm.Addresses.Get("1");This will result in this query:
GET http://localhost:2200/moviedb/Addresses(1)
To append query options to your odata request a linq-like syntax using method chaining is provided. The request has to be placed between the entity set and the corresponding .Get(), .Get(<key>) or .Count() method calls.
For example:
let comm = new MovieProxy("http://localhost:2200/moviedb", "Testproxy");
let result = await comm.Addresses.OrderBy("Street").Skip(1).Top(2).Get();will resolve in this request:
GET http://localhost:2200/moviedb/Addresses?$orderby=Street&$skip=1&$top=2
For complex requests, which are not covered by this method chaining you can use the Custom() method:
let comm = new MovieProxy("http://localhost:2200/moviedb", "Testproxy");
let result = comm.Addresses.Custom("$orderby=Street&$skip=1&top=2").Get();Supported Options:
- Select
- OrderBy
- Top
- Skip
- Filter
- Expand
- Search
- Custom
Post will add a new entry to your dataset.
let comm = new MovieProxy("http://localhost:2200/moviedb", "Testproxy");
let result = await comm.Addresses.Post({ ... });Put will replace an entry in your dataset and return the added value. The updated value will not be returned.
let comm = new MovieProxy("http://localhost:2200/moviedb", "Testproxy");
let result = await comm.Addresses.Put({ ... });Patch will update the changes in an entry of your dataset. The updated value will not be returned.
let comm = new MovieProxy("http://localhost:2200/moviedb", "Testproxy");
let result = await comm.Addresses.Patch({ ... });Delete will remove a value in your dataset. The value will not be returned.
let comm = new MovieProxy("http://localhost:2200/moviedb", "Testproxy");
let result = await comm.Addresses.Delete({ ... });Count will return the count of the entry in your dataset. This method can be combined with query options.
let comm = new MovieProxy("http://localhost:2200/moviedb", "Testproxy");
let result = await comm.Addresses.Count();