Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Github User Finder Api added #199

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions New_APIs/Github_User_Finder/README.md
Original file line number Diff line number Diff line change
@@ -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!
```
61 changes: 61 additions & 0 deletions New_APIs/Github_User_Finder/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions New_APIs/Github_User_Finder/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
41 changes: 41 additions & 0 deletions New_APIs/Github_User_Finder/server/server.js
Original file line number Diff line number Diff line change
@@ -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}`);
});
Loading