Skip to content

Commit 2059718

Browse files
Merge pull request #160 from microsoftgraph/Calling_Pattern_Doc
Added calling pattern doc
2 parents ee8c432 + ce9c478 commit 2059718

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ try {
169169
}
170170
```
171171

172-
For more information, refer: [Calling Pattern](docs/CallingPattern.md), [Actions](docs/Actions.md), [Query Params](docs/QueryParameters.md), [API Methods](docs/APIMethods.md) and [more](docs/).
172+
For more information, refer: [Calling Pattern](docs/CallingPattern.md), [Actions](docs/Actions.md), [Query Params](docs/QueryParameters.md), [API Methods](docs/OtherAPIs.md) and [more](docs/).
173173

174174
## Documentation
175175

docs/CallingPattern.md

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Calling Pattern
2+
3+
All calls to Microsoft Graph are chained together starting with **.api()**, then chain [query parameters](./QueryParameters.md) and end with an [action](./Actions.md).
4+
5+
## Path supports the following formats
6+
7+
* `me`
8+
* `/me`
9+
* `https://graph.microsoft.com/v1.0/me`
10+
* `https://graph.microsoft.com/beta/me`
11+
* `me/events?$filter=startswith(subject, "Adventure")`
12+
13+
## Promise based calling
14+
15+
Getting user details with `async`/`await`,
16+
17+
```typescript
18+
try {
19+
let res = await client.api("/me").get();
20+
console.log(res);
21+
} catch (error) {
22+
throw error;
23+
}
24+
```
25+
26+
Getting user details with `then`/`catch`,
27+
28+
```typescript
29+
client
30+
.api('/me')
31+
.get()
32+
.then((res) => {
33+
console.log(res);
34+
}).catch((err) => {
35+
console.log(err);
36+
});
37+
```
38+
39+
## Callback based calling
40+
41+
Getting user details by passing `callback`,
42+
43+
```typescript
44+
client
45+
.api('/me')
46+
.get((err, res) => {
47+
console.log(res);
48+
});
49+
```

0 commit comments

Comments
 (0)