@knowmax/http-utils
v1.0.0
Published
HTTP utilities for headers, content types, and common HTTP operations
Readme
HTTP Utils
A TypeScript library providing utilities for HTTP operations including headers and content types.
Installation
npm install @knowmax/http-utilsFeatures
- 🔧 Headers Builder: Fluent API for building HTTP headers
- 📝 Content Types: Constants for common MIME types
Usage
Headers Builder
import { headers } from '@knowmax/http-utils'
// Basic usage
const basicHeaders = headers()
.withContentTypeJson()
.withBearer('your-token')
.export()
// Advanced usage
const advancedHeaders = headers({ 'X-Custom': 'value' })
.withBearer('token123')
.withLanguage('en-US')
.withContentType('text/plain')
.withHeader('X-API-Key', 'secret')
.export()Content Types
import { CONTENTTYPE_JSON } from '@knowmax/http-utils'
// Use in your requests
headers().withContentType(CONTENTTYPE_JSON)API Reference
Headers Class
| Method | Description |
|--------|-------------|
| withBearer(token) | Add Bearer authorization |
| withLanguage(language) | Set Accept-Language (optional parameter) |
| withContentTypeJson() | Set Content-Type to application/json |
| withContentType(contentType) | Set custom Content-Type |
| withHeader(key, value) | Add custom header (ignores empty values) |
| export() | Get plain object with all headers |
Content Types
| Constant | Value |
|----------|-------|
| CONTENTTYPE_JSON | 'application/json' |
Requirements
- Node.js 16.0.0 or higher
- TypeScript 4.0+ (for TypeScript projects)
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
Made with ❤️ by Knowmax BV
