Skip to content

Commit

Permalink
getting github profiles via api
Browse files Browse the repository at this point in the history
  • Loading branch information
jayeshshaw committed Jul 2, 2023
1 parent 8dbd856 commit d9ea0fb
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions routes/api/profile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const express = require('express');
const router = express.Router();
const axios = require('axios');
const config = require('config');
const auth= require('../../middleware/auth')
const {check,validationResult}= require('express-validator')

Expand Down Expand Up @@ -253,6 +255,26 @@ router.put('/education',auth,
}
});

// @route GET api/profile/github/:username
// @desc Get user repos from Github
// @access Public
router.get('/github/:username', async (req, res) => {
try {
const uri = encodeURI(
`https://api.github.com/users/${req.params.username}/repos?per_page=5&sort=created:asc&client_id=${config.get('githubClientId')}&client_secret=${config.get('githubSecret')}`
);
const headers = {
'user-agent': 'node.js',
};
const gitHubResponse = await axios.get(uri, { headers });
return res.json(gitHubResponse.data);
}
catch (err) {
console.error(err.message);
return res.status(404).json({ msg: 'No Github profile found' });
}
});




Expand Down

0 comments on commit d9ea0fb

Please sign in to comment.