Skip to content

Commit decad06

Browse files
authored
Merge pull request #79 from deploymenttheory/dev
Dev
2 parents 59517c0 + 54801ac commit decad06

File tree

2 files changed

+119
-32
lines changed

2 files changed

+119
-32
lines changed

README.md

Lines changed: 109 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,118 @@
1-
# Template
2-
3-
This repository serves as a **Default Template Repository** according official [GitHub Contributing Guidelines][ProjectSetup] for healthy contributions. It brings you clean default Templates for several areas:
4-
5-
- [Azure DevOps Pull Requests](.azuredevops/PULL_REQUEST_TEMPLATE.md) ([`.azuredevops\PULL_REQUEST_TEMPLATE.md`](`.azuredevops\PULL_REQUEST_TEMPLATE.md`))
6-
- [Azure Pipelines](.pipelines/pipeline.yml) ([`.pipelines/pipeline.yml`](`.pipelines/pipeline.yml`))
7-
- [GitHub Workflows](.github/workflows/)
8-
- [Super Linter](.github/workflows/linter.yml) ([`.github/workflows/linter.yml`](`.github/workflows/linter.yml`))
9-
- [Sample Workflows](.github/workflows/workflow.yml) ([`.github/workflows/workflow.yml`](`.github/workflows/workflow.yml`))
10-
- [GitHub Pull Requests](.github/PULL_REQUEST_TEMPLATE.md) ([`.github/PULL_REQUEST_TEMPLATE.md`](`.github/PULL_REQUEST_TEMPLATE.md`))
11-
- [GitHub Issues](.github/ISSUE_TEMPLATE/)
12-
- [Feature Requests](.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md) ([`.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md`](`.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md`))
13-
- [Bug Reports](.github/ISSUE_TEMPLATE/BUG_REPORT.md) ([`.github/ISSUE_TEMPLATE/BUG_REPORT.md`](`.github/ISSUE_TEMPLATE/BUG_REPORT.md`))
14-
- [Codeowners](.github/CODEOWNERS) ([`.github/CODEOWNERS`](`.github/CODEOWNERS`)) _adjust usernames once cloned_
15-
- [Wiki and Documentation](docs/) ([`docs/`](`docs/`))
16-
- [gitignore](.gitignore) ([`.gitignore`](.gitignore))
17-
- [gitattributes](.gitattributes) ([`.gitattributes`](.gitattributes))
18-
- [Changelog](CHANGELOG.md) ([`CHANGELOG.md`](`CHANGELOG.md`))
19-
- [Code of Conduct](CODE_OF_CONDUCT.md) ([`CODE_OF_CONDUCT.md`](`CODE_OF_CONDUCT.md`))
20-
- [Contribution](CONTRIBUTING.md) ([`CONTRIBUTING.md`](`CONTRIBUTING.md`))
21-
- [License](LICENSE) ([`LICENSE`](`LICENSE`)) _adjust projectname once cloned_
22-
- [Readme](README.md) ([`README.md`](`README.md`))
23-
- [Security](SECURITY.md) ([`SECURITY.md`](`SECURITY.md`))
24-
1+
# Go API HTTP Client
2+
3+
This Go module offers a sophisticated HTTP client designed for seamless API interactions, with a strong emphasis on concurrency management, robust error handling, extensive logging, and adaptive rate limiting. It's particularly suitable for applications requiring high-throughput API interactions with complex authentication and operational resilience.
4+
5+
This client leverages API-specific SDKs to provide a comprehensive and consistent interface for interacting with various APIs, including Microsoft Graph, Jamf Pro, and others. It is designed to be easily extensible to support additional APIs and to be highly configurable to meet specific API requirements. It achieves this through using a modular design, with a core HTTP client and API-specific handlers that encapsulate the unique requirements of each API supported.
6+
7+
## Features
8+
9+
- **Comprehensive Authentication Support**: Robust support for various authentication schemes, including OAuth and Bearer Token, with built-in token management and validation.
10+
- **Advanced Concurrency Management**: An intelligent Concurrency Manager dynamically adjusts concurrent request limits to optimize throughput and adhere to API rate limits.
11+
- **Structured Error Handling**: Clear and actionable error reporting facilitates troubleshooting and improves reliability.
12+
- **Performance Monitoring**: Detailed performance metrics tracking provides insights into API interaction efficiency and optimization opportunities.
13+
- **Configurable Logging**: Extensive logging capabilities with customizable levels and formats aid in debugging and operational monitoring.
14+
- **Adaptive Rate Limiting**: Dynamic rate limiting automatically adjusts request rates in response to API server feedback.
15+
- **Flexible Configuration**: Extensive customization of HTTP client behavior to meet specific API requirements, including custom timeouts, retry strategies, header management, and more.
16+
- **Header Management**: Easy and efficient management of HTTP request headers, ensuring compliance with API requirements.
17+
- **Enhanced Logging with Zap**: Utilizes Uber's zap library for structured, high-performance logging, offering levels from Debug to Fatal, including structured context and dynamic adjustment based on the environment.
18+
- **API Handler Interface**: Provides a flexible and extensible way to interact with different APIs, including encoding and decoding requests and responses, managing authentication endpoints, and handling API-specific logic.
19+
20+
## API Handler
21+
22+
The `APIHandler` interface abstracts the functionality needed to interact with various APIs, making the HTTP client adaptable to different API implementations. It includes methods for constructing resource and authentication endpoints, marshaling requests, handling responses, and managing API-specific headers.
23+
24+
### Implementations
25+
26+
Currently, the HTTP client supports the following API handlers:
27+
28+
- **Jamf Pro**: Tailored for interacting with Jamf Pro's API, providing specialized methods for device management and configuration.
29+
- **Microsoft Graph**: Designed for Microsoft Graph API, enabling access to various Microsoft 365 services.
30+
31+
## Getting Started
32+
33+
### Installation
34+
35+
To use this HTTP client in your project, add the package to your Go module dependencies:
36+
37+
```bash
38+
go get github.com/yourusername/go-api-http-client
39+
```
40+
41+
### Usage
42+
Example usage with a configuration file:
43+
44+
```go
45+
package main
46+
47+
import (
48+
"fmt"
49+
"log"
50+
51+
"github.com/deploymenttheory/go-api-http-client/httpclient"
52+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
53+
)
54+
55+
func main() {
56+
configFilePath := "/path/to/clientconfig.json"
57+
loadedConfig, err := jamfpro.LoadClientConfig(configFilePath)
58+
if err != nil {
59+
log.Fatalf("Failed to load client OAuth configuration: %v", err)
60+
}
61+
62+
config := httpclient.ClientConfig{
63+
Auth: httpclient.AuthConfig{
64+
ClientID: loadedConfig.Auth.ClientID,
65+
ClientSecret: loadedConfig.Auth.ClientSecret,
66+
},
67+
Environment: httpclient.EnvironmentConfig{
68+
APIType: loadedConfig.Environment.APIType,
69+
InstanceName: loadedConfig.Environment.InstanceName,
70+
},
71+
ClientOptions: httpclient.ClientOptions{
72+
LogLevel: loadedConfig.ClientOptions.LogLevel,
73+
HideSensitiveData: loadedConfig.ClientOptions.HideSensitiveData,
74+
LogOutputFormat: loadedConfig.ClientOptions.LogOutputFormat,
75+
},
76+
}
77+
78+
client, err := jamfpro.BuildClient(config)
79+
if err != nil {
80+
log.Fatalf("Failed to create client: %v", err)
81+
}
82+
}
83+
84+
```
85+
86+
Example configuration file (clientconfig.json):
87+
88+
```json
89+
{
90+
"Auth": {
91+
"ClientID": "client-id",
92+
"ClientSecret": "client-secret",
93+
"Username": "username",
94+
"Password": "password"
95+
},
96+
"Environment": {
97+
"InstanceName": "yourinstance",
98+
"OverrideBaseDomain": "",
99+
"APIType": "" // "jamfpro" / "graph"
100+
},
101+
"ClientOptions": {
102+
"LogLevel": "LogLevelDebug", // "LogLevelDebug" / "LogLevelInfo" / "LogLevelWarn" / "LogLevelError" / "LogLevelFatal" / "LogLevelPanic"
103+
"LogOutputFormat": "console", // "console" / "json"
104+
"LogConsoleSeparator": " ", // " " / "\t" / "," / etc.
105+
"HideSensitiveData": true, // true / false
106+
}
107+
}
108+
```
25109

26110
## Status
27111

28112
[![Super Linter](<https://github.com/segraef/Template/actions/workflows/linter.yml/badge.svg>)](<https://github.com/segraef/Template/actions/workflows/linter.yml>)
29113

30114
[![Sample Workflow](<https://github.com/segraef/Template/actions/workflows/workflow.yml/badge.svg>)](<https://github.com/segraef/Template/actions/workflows/workflow.yml>)
31115

32-
## Creating a repository from a template
33-
34-
You can [generate](https://github.com/segraef/Template/generate) a new repository with the same directory structure and files as an existing repository. More details can be found [here][CreateFromTemplate].
35116

36117
## Reporting Issues and Feedback
37118

@@ -43,7 +124,7 @@ If you are taking the time to mention a problem, even a seemingly minor one, it
43124

44125
## Feedback
45126

46-
If there is a feature you would like to see in here, please file an issue or feature request in the [GitHub Issues][GitHubIssues] page to provide direct feedback.
127+
Contributions are welcome to make this HTTP client even better! Feel free to fork the repository, make your improvements, and submit a pull request. For major changes or new features, please file an issue or feature request in the [GitHub Issues][GitHubIssues] page to discuss what you would like to change.
47128

48129
## Contribution
49130

httpclient/httpclient_rate_handler.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33
/*
44
Components:
55
6-
Backoff Strategy: A function that calculates the delay before the next retry. It will implement exponential backoff with jitter. This strategy is more effective than a fixed delay, as it ensures that in cases of prolonged issues, the client won't keep hammering the server with a high frequency.
7-
Response Time Monitoring: We'll introduce a mechanism to track average response times and use deviations from this average to inform our backoff strategy.
8-
Error Classifier: A function to classify different types of errors. Only transient errors should be retried.
9-
Rate Limit Header Parser: For future compatibility, a function that can parse common rate limit headers (like X-RateLimit-Remaining and Retry-After) and adjust behavior accordingly.
6+
Backoff Strategy: A function that calculates the delay before the next retry. It will
7+
implement exponential backoff with jitter. This strategy is more effective than a fixed
8+
delay, as it ensures that in cases of prolonged issues, the client won't keep hammering
9+
the server with a high frequency.
10+
Response Time Monitoring: We'll introduce a mechanism to track average response times and
11+
use deviations from this average to inform our backoff strategy.
12+
Error Classifier: A function to classify different types of errors. Only transient errors
13+
should be retried.Rate Limit Header Parser: For future compatibility, a function that can
14+
parse common rate limit headers (like X-RateLimit-Remaining and Retry-After) and adjust
15+
behavior accordingly.
1016
1117
*/
1218

0 commit comments

Comments
 (0)