Skip to content

Commit

Permalink
Updated documentation and fixed example.
Browse files Browse the repository at this point in the history
  • Loading branch information
janhommes committed Feb 19, 2019
1 parent fa00d97 commit a76d982
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
52 changes: 51 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,61 @@ window.odata
const o = require('odata');
// promise example
await o('http://my.url')
o('http://my.url')
.get('resource')
.then((data) => console.log(data));
```
## CRUD examples
> The following examples using async/await but for simplicity we removed the async deceleration. To make that work this example must be wrapped in an async function or use promise.
### **C**reate (POST):
```javascript
const data = {
FirstName: "Bar",
LastName: "Foo",
UserName: "foobar",
}
const response = await o('http://my.url')
.post('User', data)
.query();
console.log(response); // E.g. the user
```
### **R**ead (GET):
```javascript
const response = await o('http://my.url')
.get('User')
.query({$filter: `UserName eq 'foobar'`});
console.log(response); // If one -> the exact user, otherwise an array of users
```
### **U**pdate (Patch):
```javascript
const data = {
FirstName: 'John'
}
const response = await o('http://my.url')
.patch(`User('foobar')`, data)
.query();
console.log(response); // The result of the patch, e.g. the status code
```
### **D**elete:
```javascript
const response = await o('http://my.url')
.delete(`User('foobar')`)
.query();
console.log(response); // The status code
```
## Options
You can pass as a second option into the `o` constructor options. The signature is:
```typescript
Expand Down
2 changes: 1 addition & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ <h2 data-bind="text:LastName"></h4>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/q.js"></script>
<script src="../dist/umd/o.js"></script>
<script src="https://unpkg.com/[email protected]/dist/umd/o.min.js"></script>
<script src="js/knockout-3.2.0.js"></script>
<script src="js/ko.bindinghandler.currency.js"></script>
<script src="browser.js"></script>
Expand Down

0 comments on commit a76d982

Please sign in to comment.