api-hub-client
v1.0.0
Published
This is a API Hub client for the API routes
Readme
Overview
api-hub-client provides a developer-friendly TypeScript interface to interact with the api-hub server.
It simplifies API calls by handling requests, responses, and type definitions automatically, enabling type-safe and maintainable integration in frontend or Node.js applications.
Features
- Fully typed TypeScript API for IntelliSense and compile-time safety
- Async/await interface for all requests
- Supports all endpoints exposed by the
api-hubserver - Easy configuration with
baseUrl - Handles errors and responses consistently
Supported API Endpoints
| Module | Endpoint | Description | Example Method |
|------------|----------|------------|----------------|
| GitHub | /github/repos/:username | Fetch GitHub repositories for a given username | client.github.getRepos(username) |
| YouTube | /youtube/search/:query | Search YouTube videos by query | client.youtube.search(query) |
| TheMealDB | /mealdb/search/:query | Search for meals and recipes | client.mealdb.search(query) |
| NewsAPI | /newsapi/top-headlines | Fetch latest news articles | client.newsapi.topHeadlines(country) |
| Weather | /weather/current/:city | Get current weather info for a city | client.weather.getCurrent(city) |
Click the module name to view the corresponding backend route implementation.
Project Structure
api-hub-client/
├── src/
│ ├── index.ts # Entry point exporting ApiHubClient class
│ ├── client.ts # HTTP client implementation
│ └── types/ # TypeScript types for requests and responses
├── package.json
├── tsconfig.json
├── README.md
└── .env.examplePrerequisites
- Node.js v18 or later
- npm, yarn, or pnpm
- Access to a running
api-hubserver
Installation
Install the package in your project:
npm install api-hub-client
# or
yarn add api-hub-clientConfiguration
Create an instance of the client with your API Hub server base URL:
import { ApiHubClient } from "api-hub-client";
const client = new ApiHubClient({
baseUrl: "http://localhost:8080",
});Usage Examples
Fetch GitHub Repositories
const repos = await client.github.getRepos("facebook");
console.log(repos);Search TheMealDB
const recipes = await client.mealdb.search("carbonara");
console.log(recipes);Search YouTube
const videos = await client.youtube.search("nextjs tutorial");
console.log(videos);TypeScript Support
Provides types for:
- Request parameters
- API responses
- Error handling
- Optional pagination helpers
This ensures full IntelliSense and compile-time safety.
Development
cd api-hub-client
npm install
npm run buildLink the client locally for testing:
npm linkEnsure the
api-hubserver is running for real-time testing.
Scripts
| Command | Description |
| --------------- | --------------------------------- |
| npm run dev | Start development with watch mode |
| npm run build | Compile TypeScript to JavaScript |
| npm test | Run unit tests (if available) |
Contributing
This package follows the monorepo contribution guidelines.
Please review CONTRIBUTING.md before submitting a pull request.
License
MIT
