-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenGithub.js
More file actions
43 lines (36 loc) · 1.19 KB
/
openGithub.js
File metadata and controls
43 lines (36 loc) · 1.19 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
function decodeApiResponse(apiRespone) {
var result = JSON.parse(apiRespone)
var response = JSON.parse(result.response)
return response
}
function fetchAndDisplayEmployees () {
var employeeListResponse = httpGet("http://dummy.restapiexample.com/api/v1/employees")
var response = decodeApiResponse(employeeListResponse)
var employeesList = response.data
employeesList.forEach(function (data) {
log("https://www.google.com" + data.employee_name, "blue")
})
}
function createEmployeeAndDisplay () {
var employeeCreateResponse = httpPost(
"http://dummy.restapiexample.com/api/v1/create",
JSON.stringify({
"name": "Manoj Singh Negi",
"salary": "15",
"age": "22"
}),
{
"content-type": "application/json"
}
)
var response = decodeApiResponse(employeeCreateResponse)
if (response.status === "success") {
notify("Employee created", "success", 3000)
Object.keys(response.data)
.forEach(function (key) {
log(key + ": " + response.data[key], "blue")
})
}
}
fetchAndDisplayEmployees()
createEmployeeAndDisplay()