https://github.com/dillendev/training-hourly
Demo API client for a fake time management tool called: Hourly
https://github.com/dillendev/training-hourly
Last synced: about 1 month ago
JSON representation
Demo API client for a fake time management tool called: Hourly
- Host: GitHub
- URL: https://github.com/dillendev/training-hourly
- Owner: dillendev
- License: mit
- Created: 2023-01-31T12:35:34.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-03T14:52:35.000Z (over 3 years ago)
- Last Synced: 2024-06-21T13:07:52.903Z (about 2 years ago)
- Language: Go
- Size: 44.9 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Hourly
## REST API
The Hourly API is a REST API and includes an [OpenAPI specification](https://app.swaggerhub.com/apis-docs/dillen.dev/hourly-api/0.0.1) . It isn't published on the internet but can be run locally by using the following command:
```bash
go run github.com/dillendev/training-hourly/cmd/server@latest
```
This will run the Hourly API on port 8989 on localhost and contains the actual data for the assignment.
## Go client
The Go client is a client for the Hourly API. It can be used to retrieve the data from the API and can be used to create a CLI or a web application. Note that it requires authorization by using a token. The token can be retrieved by using the `/api/auth/tokens` endpoint.
### Usage
```go
package main
import (
"github.com/deepmap/oapi-codegen/pkg/securityprovider"
hourly "github.com/dillendev/training-hourly"
)
func main() {
// Setup bearer token authentication
provider, err := securityprovider.NewSecurityProviderBearerToken("my-token")
if err != nil {
panic(err)
}
// Setup client-side middleware to add the authorization header
authOption := hourly.WithRequestEditorFn(provider.Intercept)
// Create a new client for the Hourly API with the middleware
client, err := hourly.NewClientWithResponses("http://localhost:8989", authOption)
if err != nil {
panic(err)
}
// Do something with: client
}
```