From 02b71d97312126a56d8f566b801630c560165278 Mon Sep 17 00:00:00 2001 From: Vipul_Lakum Date: Sat, 1 Jun 2024 19:16:05 +0530 Subject: [PATCH] Github User Finder Api added --- New_APIs/Github_User_Finder/README.md | 111 ++++++++++++++++++ New_APIs/Github_User_Finder/package-lock.json | 61 ++++++++++ New_APIs/Github_User_Finder/package.json | 21 ++++ New_APIs/Github_User_Finder/server/server.js | 41 +++++++ 4 files changed, 234 insertions(+) create mode 100644 New_APIs/Github_User_Finder/README.md create mode 100644 New_APIs/Github_User_Finder/package-lock.json create mode 100644 New_APIs/Github_User_Finder/package.json create mode 100644 New_APIs/Github_User_Finder/server/server.js diff --git a/New_APIs/Github_User_Finder/README.md b/New_APIs/Github_User_Finder/README.md new file mode 100644 index 0000000..b71f5a0 --- /dev/null +++ b/New_APIs/Github_User_Finder/README.md @@ -0,0 +1,111 @@ +Here's the complete README.md file for your GitHub User Finder API: + +````markdown +# GitHub User Finder API + +This GitHub User Finder API allows users to retrieve details of GitHub users and their repositories using their GitHub username. + +## Features + +- Retrieve GitHub user details +- Retrieve repositories of a GitHub user + +## Installation + +1. Clone the repository: + ```bash + git clone https://github.com/your-username/github-user-finder-api.git + cd github-user-finder-api + ``` +```` + +2. Install Dependencies: + ```bash + npm install + ``` + +## Usage + +Start the server: + +```bash +node server.js +``` + +The server will be hosted on port 3000, you can access it on [http://localhost:3000](http://localhost:3000). + +## Endpoints + +### Retrieve GitHub User Details + +- URL: `/users/:username` +- Method: GET +- Description: Retrieve details of a GitHub user by their username. +- Example Response: + ```json + { + "login": "octocat", + "id": 1, + "avatar_url": "https://github.com/images/error/octocat_happy.gif", + "name": "monalisa octocat", + "company": "GitHub", + "blog": "https://github.com/blog", + "location": "San Francisco", + "email": "octocat@github.com", + "bio": "There once was...", + "public_repos": 2, + "followers": 20, + "following": 0, + "created_at": "2008-01-14T04:33:35Z" + } + ``` + +### Retrieve GitHub User Repositories + +- URL: `/users/:username/repos` +- Method: GET +- Description: Retrieve repositories of a GitHub user by their username. +- Example Response: + ```json + [ + { + "id": 1296269, + "name": "Hello-World", + "full_name": "octocat/Hello-World", + "owner": { + "login": "octocat", + "id": 1, + "avatar_url": "https://github.com/images/error/octocat_happy.gif" + }, + "private": false, + "html_url": "https://github.com/octocat/Hello-World", + "description": "This your first repo!", + "fork": false, + "created_at": "2011-01-26T19:01:12Z", + "updated_at": "2011-01-26T19:14:43Z", + "pushed_at": "2011-01-26T19:14:43Z", + "homepage": "https://github.com", + "size": 108, + "stargazers_count": 80, + "watchers_count": 80, + "language": "Ruby", + "forks_count": 9, + "open_issues_count": 0, + "master_branch": "master", + "default_branch": "master" + } + ] + ``` + +## Dependencies + +- Express: Fast, unopinionated, minimalist web framework for Node.js. +- Axios: Promise-based HTTP client for the browser and Node.js. + +## License + +This project is licensed under the MIT License - see the LICENSE file for details. + +``` +Feel free to adjust any parts as needed! +``` diff --git a/New_APIs/Github_User_Finder/package-lock.json b/New_APIs/Github_User_Finder/package-lock.json new file mode 100644 index 0000000..9ef24b3 --- /dev/null +++ b/New_APIs/Github_User_Finder/package-lock.json @@ -0,0 +1,61 @@ +{ + "name": "github-user-finder-api", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "axios": { + "version": "0.26.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.26.0.tgz", + "integrity": "sha512-gXtNLz3QCjFvChx9G1JfH8cIFp+2u9te/nvYtFVHBJFK8jup6fV4/f6c8H+TdRf6uSGrJlNZESW2nUfbA9TLEg==", + "dev": false, + "requires": { + "follow-redirects": "^1.14.5" + } + }, + "express": { + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/express/-/express-4.17.2.tgz", + "integrity": "sha512-waf2EfmeMwme3I5xT+xhIL3s+b0/CaZ/MW7m1NeqqsF6R8FukttUaNy1ZsFqDyDUuweqyM9xB+F1GBBhK5femZg==", + "dev": false, + "requires": { + "accepts": "~1.3.7", + "array-flatten": "1.1.1", + "body-parser": "1.19.0", + "content-disposition": "0.5.3", + "content-type": "~1.0.4", + "cookie": "0.4.0", + "cookie-signature": "1.0.6", + "debug": "2.6.9", + "depd": "~1.1.2", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "finalhandler": "~1.1.2", + "fresh": "0.5.2", + "merge-descriptors": "1.0.1", + "methods": "~1.1.2", + "on-finished": "~2.3.0", + "parseurl": "~1.3.3", + "path-to-regexp": "0.1.7", + "proxy-addr": "~2.0.6", + "qs": "6.7.0", + "range-parser": "~1.2.1", + "safe-buffer": "5.2.1", + "send": "0.17.1", + "serve-static": "1.14.1", + "setprototypeof": "1.1.1", + "statuses": "~1.5.0", + "type-is": "~1.6.18", + "utils-merge": "1.0.1", + "vary": "~1.1.2" + } + }, + "follow-redirects": { + "version": "1.14.5", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.5.tgz", + "integrity": "sha512-5O+2wzTNmkixwH3/A27NgaS5J0fX35vK5wXY4d2MEXoaa8xBPwEs9OXpENYU4qo8mP4g6LW1FCGSp97HYfukRw==", + "dev": false + } + } +} \ No newline at end of file diff --git a/New_APIs/Github_User_Finder/package.json b/New_APIs/Github_User_Finder/package.json new file mode 100644 index 0000000..8ddce63 --- /dev/null +++ b/New_APIs/Github_User_Finder/package.json @@ -0,0 +1,21 @@ +{ + "name": "github-user-finder-api", + "version": "1.0.0", + "description": "GitHub User Finder API to retrieve user details and repositories", + "main": "server.js", + "scripts": { + "start": "node server.js" + }, + "keywords": [ + "GitHub", + "API", + "Node.js", + "Express.js" + ], + "author": "Vipul Lakum", + "license": "MIT", + "dependencies": { + "axios": "^0.26.0", + "express": "^4.17.2" + } +} \ No newline at end of file diff --git a/New_APIs/Github_User_Finder/server/server.js b/New_APIs/Github_User_Finder/server/server.js new file mode 100644 index 0000000..bdfe2ef --- /dev/null +++ b/New_APIs/Github_User_Finder/server/server.js @@ -0,0 +1,41 @@ +const express = require('express'); +const axios = require('axios'); + +const app = express(); +const port = 3000; + +// GitHub API base URL +const GITHUB_API_BASE_URL = 'https://api.github.com/users'; + +// Endpoint to retrieve details of a GitHub user by username +app.get('/users/:username', async (req, res) => { + const { username } = req.params; + try { + // Make a GET request to GitHub API to fetch user details + const response = await axios.get(`${GITHUB_API_BASE_URL}/${username}`); + // Respond with the user details + res.json(response.data); + } catch (error) { + // Handle errors (e.g., user not found) + res.status(404).json({ message: 'User not found' }); + } +}); + +// Endpoint to retrieve repositories of a GitHub user by username +app.get('/users/:username/repos', async (req, res) => { + const { username } = req.params; + try { + // Make a GET request to GitHub API to fetch user repositories + const response = await axios.get(`${GITHUB_API_BASE_URL}/${username}/repos`); + // Respond with the list of repositories + res.json(response.data); + } catch (error) { + // Handle errors (e.g., user not found or no repositories available) + res.status(404).json({ message: 'User not found or no repositories available' }); + } +}); + +// Start the server and listen on the specified port +app.listen(port, () => { + console.log(`Server is running on http://localhost:${port}`); +});