Skip to content

Commit

Permalink
Add non-authenticated example to README (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
optik-aper authored Dec 11, 2023
1 parent 679de77 commit ec9fca1
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ go get -u github.com/vultr/govultr/v3

## Usage

Vultr uses a PAT (Personal Access token) to interact/authenticate with the APIs. Generate an API Key from the [API menu](https://my.vultr.com/settings/#settingsapi) in the Vultr Customer Portal.
Vultr uses a personal access token (PAT) to interact/authenticate with the
APIs. Generate an API Key from the [API menu](https://my.vultr.com/settings/#settingsapi)
in the Vultr Customer Portal.

To instantiate a GoVultr client, invoke `NewClient()`. You must pass your `PAT` to an `oauth2` library to create the `*http.Client`, which configures the `Authorization` header with your PAT as the `bearer api-key`.
To instantiate a GoVultr client, invoke `NewClient()`. Most operations require
that you pass a PAT to an `oauth2` library to create the `*http.Client`, which
configures the `Authorization` header with your PAT as the `bearer api-key`. If
a PAT is not provided, public operations like listing plans or applications
will still work.

The client has three optional parameters:

Expand Down Expand Up @@ -53,6 +59,19 @@ func main() {
}
```

Passing `nil` to `NewClient` will work for routes that do not require
authentication.

```go
...

vultrClient := govultr.NewClient(nil)
ctx := context.Background()
plans, _, _, err := vultrClient.Plan.List(ctx, "", nil)

...
```

### Example Usage

Create a VPS
Expand All @@ -77,7 +96,9 @@ if err != nil {

## Pagination

GoVultr v2 introduces pagination for all list calls. Each list call returns a `meta` struct containing the total amount of items in the list and next/previous links to navigate the paging.
GoVultr v2 introduces pagination for all list calls. Each list call returns a
`meta` struct containing the total amount of items in the list and
next/previous links to navigate the paging.

```go
// Meta represents the available pagination information
Expand All @@ -93,9 +114,12 @@ type Links struct {
}

```
Pass a `per_page` value to the `list_options` struct to adjust the number of items returned per call. The default is 100 items per page and max is 500 items per page.
Pass a `per_page` value to the `list_options` struct to adjust the number of
items returned per call. The default is 100 items per page and max is 500 items
per page.

This example demonstrates how to retrieve all of your instances, with one instance per page.
This example demonstrates how to retrieve all of your instances, with one
instance per page.

```go
listOptions := &govultr.ListOptions{PerPage: 1}
Expand All @@ -118,7 +142,9 @@ for {
```
## Versioning

This project follows [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/vultr/govultr/tags).
This project follows [SemVer](http://semver.org/) for versioning. For the
versions available, see the [tags on this
repository](https://github.com/vultr/govultr/tags).

## Documentation

Expand Down

0 comments on commit ec9fca1

Please sign in to comment.