# README

Go API client for openapi

About this spec

The IPFS Pinning Service API is intended to be an implementation-agnostic API:

  • For use and implementation by pinning service providers
  • For use in client mode by IPFS nodes and GUI-based applications

Note: while ready for implementation, this spec is still a work in progress! 🏗️ Your input and feedback are welcome and valuable as we develop this API spec. Please join the design discussion at github.com/ipfs/pinning-services-api-spec.

Schemas

This section describes the most important object types and conventions.

A full list of fields and schemas can be found in the schemas section of the YAML file.

Identifiers

cid

Content Identifier (CID) points at the root of a DAG that is pinned recursively.

requestid

Unique identifier of a pin request.

When a pin is created, the service responds with unique requestid that can be later used for pin removal. When the same cid is pinned again, a different requestid is returned to differentiate between those pin requests.

Service implementation should use UUID, hash(accessToken,Pin,PinStatus.created), or any other opaque identifier that provides equally strong protection against race conditions.

Objects

Pin object

pin object

The Pin object is a representation of a pin request.

It includes the cid of data to be pinned, as well as optional metadata in name, origins, and meta.

Pin status response

pin status response object

The PinStatus object is a representation of the current state of a pinning operation. It includes the original pin object, along with the current status and globally unique requestid of the entire pinning request, which can be used for future status checks and management. Addresses in the delegates array are peers delegated by the pinning service for facilitating direct file transfers (more details in the provider hints section). Any additional vendor-specific information is returned in optional info.

The pin lifecycle

pinning service objects and lifecycle

Creating a new pin object

The user sends a Pin object to POST /pins and receives a PinStatus response:

  • requestid in PinStatus is the identifier of the pin operation, which can can be used for checking status, and removing the pin in the future
  • status in PinStatus indicates the current state of a pin

Checking status of in-progress pinning

status (in PinStatus) may indicate a pending state (queued or pinning). This means the data behind Pin.cid was not found on the pinning service and is being fetched from the IPFS network at large, which may take time.

In this case, the user can periodically check pinning progress via GET /pins/{requestid} until pinning is successful, or the user decides to remove the pending pin.

Replacing an existing pin object

The user can replace an existing pin object via POST /pins/{requestid}. This is a shortcut for removing a pin object identified by requestid and creating a new one in a single API call that protects against undesired garbage collection of blocks common to both pins. Useful when updating a pin representing a huge dataset where most of blocks did not change. The new pin object requestid is returned in the PinStatus response. The old pin object is deleted automatically.

Removing a pin object

A pin object can be removed via DELETE /pins/{requestid}.

Provider hints

Pinning of new data can be accelerated by providing a list of known data sources in Pin.origins, and connecting at least one of them to pinning service nodes at PinStatus.delegates.

The most common scenario is a client putting its own IPFS node's multiaddrs in Pin.origins, and then directly connecting to every multiaddr returned by a pinning service in PinStatus.delegates to initiate transfer.

This ensures data transfer starts immediately (without waiting for provider discovery over DHT), and direct dial from a client works around peer routing issues in restrictive network topologies such as NATs.

Custom metadata

Pinning services are encouraged to add support for additional features by leveraging the optional Pin.meta and PinStatus.info fields. While these attributes can be application- or vendor-specific, we encourage the community at large to leverage these attributes as a sandbox to come up with conventions that could become part of future revisions of this API.

Pin metadata

String keys and values passed in Pin.meta are persisted with the pin object.

Potential uses:

  • Pin.meta[app_id]: Attaching a unique identifier to pins created by an app enables filtering pins per app via ?meta={\"app_id\":<UUID>}
  • Pin.meta[vendor_policy]: Vendor-specific policy (for example: which region to use, how many copies to keep)

Note that it is OK for a client to omit or ignore these optional attributes; doing so should not impact the basic pinning functionality.

Pin status info

Additional PinStatus.info can be returned by pinning service.

Potential uses:

  • PinStatus.info[status_details]: more info about the current status (queue position, percentage of transferred data, summary of where data is stored, etc); when PinStatus.status=failed, it could provide a reason why a pin operation failed (e.g. lack of funds, DAG too big, etc.)
  • PinStatus.info[dag_size]: the size of pinned data, along with DAG overhead
  • PinStatus.info[raw_size]: the size of data without DAG overhead (eg. unixfs)
  • PinStatus.info[pinned_until]: if vendor supports time-bound pins, this could indicate when the pin will expire

Pagination and filtering

Pin objects can be listed by executing GET /pins with optional parameters:

  • When no filters are provided, the endpoint will return a small batch of the 10 most recently created items, from the latest to the oldest.
  • The number of returned items can be adjusted with the limit parameter (implicit default is 10).
  • If the value in PinResults.count is bigger than the length of PinResults.results, the client can infer there are more results that can be queried.
  • To read more items, pass the before filter with the timestamp from PinStatus.created found in the oldest item in the current batch of results. Repeat to read all results.
  • Returned results can be fine-tuned by applying optional after, cid, name, status, or meta filters.

Note: pagination by the created timestamp requires each value to be globally unique. Any future considerations to add support for bulk creation must account for this.

Overview

This API client was generated by the OpenAPI Generator project. By using the OpenAPI-spec from a remote server, you can easily generate an API client.

  • API version: 0.1.1
  • Package version: 1.0.0
  • Build package: org.openapitools.codegen.languages.GoClientExperimentalCodegen

Installation

Install the following dependencies:

go get github.com/stretchr/testify/assert
go get golang.org/x/oauth2
go get golang.org/x/net/context

Put the package under your project folder and add the following in import:

import sw "./openapi"

Configuration of Server URL

Default configuration comes with Servers field that contains server objects as defined in the OpenAPI specification.

Select Server Configuration

For using other server than the one defined on index 0 set context value sw.ContextServerIndex of type int.

ctx := context.WithValue(context.Background(), sw.ContextServerIndex, 1)

Templated Server URL

Templated server URL is formatted using default variables from configuration or from context value sw.ContextServerVariables of type map[string]string.

ctx := context.WithValue(context.Background(), sw.ContextServerVariables, map[string]string{
	"basePath": "v2",
})

Note, enum values are always validated and all unused variables are silently ignored.

URLs Configuration per Operation

Each operation can use different server URL defined using OperationServers map in the Configuration. An operation is uniquely identifield by "{classname}Service.{nickname}" string. Similar rules for overriding default operation server index and variables applies by using sw.ContextOperationServerIndices and sw.ContextOperationServerVariables context maps.

ctx := context.WithValue(context.Background(), sw.ContextOperationServerIndices, map[string]int{
	"{classname}Service.{nickname}": 2,
})
ctx = context.WithValue(context.Background(), sw.ContextOperationServerVariables, map[string]map[string]string{
	"{classname}Service.{nickname}": {
		"port": "8443",
	},
})

Documentation for API Endpoints

All URIs are relative to https://pinning-service.example.com

ClassMethodHTTP requestDescription
PinsApiPinsGetGet /pinsList pin objects
PinsApiPinsPostPost /pinsAdd pin object
PinsApiPinsRequestidDeleteDelete /pins/{requestid}Remove pin object
PinsApiPinsRequestidGetGet /pins/{requestid}Get pin object
PinsApiPinsRequestidPostPost /pins/{requestid}Replace pin object

Documentation For Models

Documentation For Authorization

accessToken

Documentation for Utility Methods

Due to the fact that model structure members are all pointers, this package contains a number of utility functions to easily obtain pointers to values of basic types. Each of these functions takes a value of the given basic type and returns a pointer to it:

  • PtrBool
  • PtrInt
  • PtrInt32
  • PtrInt64
  • PtrFloat
  • PtrFloat32
  • PtrFloat64
  • PtrString
  • PtrTime

Author

# Functions

CacheExpires helper function to determine remaining time before repeating a request.
NewAPIClient creates a new API client.
NewAPIResponse returns a new APIResonse object.
NewAPIResponseWithError returns a new APIResponse object with the provided error message.
NewConfiguration returns a new Configuration object Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NewConfiguration.
NewFailure instantiates a new Failure object This constructor will assign default values to properties that have it defined, and makes sure properties required by API are set, but the set of arguments will change when the set of required properties is changed Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NewFailure.
NewFailureError instantiates a new FailureError object This constructor will assign default values to properties that have it defined, and makes sure properties required by API are set, but the set of arguments will change when the set of required properties is changed Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NewFailureError.
NewFailureErrorWithDefaults instantiates a new FailureError object This constructor will only assign default values to properties that have it defined, but it doesn't guarantee that properties required by API are set Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NewFailureErrorWithDefaults.
NewFailureWithDefaults instantiates a new Failure object This constructor will only assign default values to properties that have it defined, but it doesn't guarantee that properties required by API are set Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NewFailureWithDefaults.
Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NewNullableBool.
Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NewNullableFailure.
Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NewNullableFailureError.
Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NewNullableFloat32.
Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NewNullableFloat64.
Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NewNullableInt.
Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NewNullableInt32.
Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NewNullableInt64.
Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NewNullablePin.
Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NewNullablePinResults.
Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NewNullablePinStatus.
Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NewNullableStatus.
Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NewNullableString.
Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NewNullableTime.
NewPin instantiates a new Pin object This constructor will assign default values to properties that have it defined, and makes sure properties required by API are set, but the set of arguments will change when the set of required properties is changed Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NewPin.
NewPinResults instantiates a new PinResults object This constructor will assign default values to properties that have it defined, and makes sure properties required by API are set, but the set of arguments will change when the set of required properties is changed Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NewPinResults.
NewPinResultsWithDefaults instantiates a new PinResults object This constructor will only assign default values to properties that have it defined, but it doesn't guarantee that properties required by API are set Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NewPinResultsWithDefaults.
NewPinStatus instantiates a new PinStatus object This constructor will assign default values to properties that have it defined, and makes sure properties required by API are set, but the set of arguments will change when the set of required properties is changed Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NewPinStatus.
NewPinStatusWithDefaults instantiates a new PinStatus object This constructor will only assign default values to properties that have it defined, but it doesn't guarantee that properties required by API are set Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NewPinStatusWithDefaults.
NewPinWithDefaults instantiates a new Pin object This constructor will only assign default values to properties that have it defined, but it doesn't guarantee that properties required by API are set Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NewPinWithDefaults.
PtrBool is a helper routine that returns a pointer to given integer value.
PtrFloat32 is a helper routine that returns a pointer to given float value.
PtrFloat64 is a helper routine that returns a pointer to given float value.
PtrInt is a helper routine that returns a pointer to given integer value.
PtrInt32 is a helper routine that returns a pointer to given integer value.
PtrInt64 is a helper routine that returns a pointer to given integer value.
PtrString is a helper routine that returns a pointer to given string value.
PtrTime is helper routine that returns a pointer to given Time value.

# Constants

Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.FAILED.
Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.PINNED.
Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.PINNING.
Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.QUEUED.

# Variables

ContextAccessToken takes a string oauth2 access token as authentication for the request.
ContextAPIKeys takes a string apikey as authentication for the request Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.ContextAPIKeys.
ContextBasicAuth takes BasicAuth as authentication for the request.
ContextHttpSignatureAuth takes HttpSignatureAuth as authentication for the request.
ContextOAuth2 takes an oauth2.TokenSource as authentication for the request.
ContextOperationServerIndices uses a server configuration from the index mapping.
ContextOperationServerVariables overrides a server configuration variables using operation specific values.
ContextServerIndex uses a server configuration from the index.
ContextServerVariables overrides a server configuration variables.

# Structs

APIClient manages communication with the IPFS Pinning Service API API v0.1.1 In most cases there should be only one, shared, APIClient.
APIKey provides API key based authentication to a request passed via context using ContextAPIKey Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.APIKey.
APIResponse stores the API response returned by the server.
BasicAuth provides basic http authentication to a request passed via context using ContextBasicAuth Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.BasicAuth.
Configuration stores the configuration of the API client Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.Configuration.
Failure Response for a failed request Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.Failure.
FailureError struct for FailureError Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.FailureError.
GenericOpenAPIError Provides access to the body, error and model on returned errors.
Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NullableBool.
Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NullableFailure.
Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NullableFailureError.
Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NullableFloat32.
Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NullableFloat64.
Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NullableInt.
Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NullableInt32.
Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NullableInt64.
Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NullablePin.
Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NullablePinResults.
Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NullablePinStatus.
Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NullableStatus.
Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NullableString.
Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.NullableTime.
Pin Pin object Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.Pin.
PinResults Response used for listing pin objects matching request Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.PinResults.
PinStatus Pin object with status Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.PinStatus.
ServerConfiguration stores the information about a server Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.ServerConfiguration.
ServerVariable stores the information about a server variable Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.ServerVariable.

# Type aliases

PinsApiService PinsApi service Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.PinsApiService.
ServerConfigurations stores multiple ServerConfiguration items Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.ServerConfigurations.
Status Status a pin object can have at a pinning service Deprecated: use github.com/ipfs/boxo/pinning/remote/client/openapi.Status.