8000 Add Fetch example (#105) · mlchiang/quickstart-js@c159296 · GitHub
[go: up one dir, main page]

Skip to content

Commit c159296

Browse filesBrowse files
Add Fetch example (firebase#105)
1 parent 2aad64e commit c159296

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

messaging/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,34 @@ Content-Type: application/json
4646
}
4747
```
4848

49+
### Fetch
50+
```js
51+
var key = 'YOUR-SERVER-KEY';
52+
var to = 'YOUR-IID-TOKEN';
53+
var notification = {
54+
'title': 'Portugal vs. Denmark',
55+
'body': '5 to 1',
56+
'icon': 'firebase-logo.png',
57+
'click_action': 'http://localhost:8081'
58+
};
59+
60+
fetch('https://fcm.googleapis.com/fcm/send', {
61+
'method': 'POST',
62+
'headers': {
63+
'Authorization': 'key=' + key,
64+
'Content-Type': 'application/json'
65+
},
66+
'body': JSON.stringify({
67+
'notification': notification,
68+
'to': to
69+
})
70+
}).then(function(response) {
71+
console.log(response);
72+
}).catch(function(error) {
73+
console.error(error);
74+
})
75+
```
76+
4977
### cURL
5078
```
5179
curl -X POST -H "Authorization: key=YOUR-SERVER-KEY" -H "Content-Type: application/json" -d '{

0 commit comments

Comments
 (0)
0