-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetusers.js
More file actions
32 lines (28 loc) · 850 Bytes
/
getusers.js
File metadata and controls
32 lines (28 loc) · 850 Bytes
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
const axios = require('axios');
exports.handler = function(event, context, callback){
const { API_URL, API_CLIENT_ID, API_CLIENT_SECRET } = process.env;
const URL = `https://api.github.com/users/pranitcode/repos?type=owner&sort=updated&client_id=${API_CLIENT_ID}&client_secret=${API_CLIENT_SECRET}`;
// Send user response
const send = body => {
callback(null, {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers':
'Origin, X-Requested-With, Content-Type, Accept'
},
body: JSON.stringify(body)
});
}
// Perform API call
const getUsers = () => {
axios.get(URL)
.then(res => send(res.data))
.catch(err => send(err));
}
// Make sure method is GET
if(event.httpMethod == 'GET') {
// Run
getUsers();
}
}