packngo icon indicating copy to clipboard operation
packngo copied to clipboard

escape hatch for consuming unsupported endpoints and data types

Open displague opened this issue 3 years ago • 0 comments

If a new API endpoint or data type is created that is not well-defined by this client, this client should offer functions that simplify consumption of those endpoints and data-types.

Features that this client can provide:

  • support for pagination
  • support for ref includes/exclude parameters
  • support for sort/order and search parameters
  • knowing how to fetch API tokens from common configuration
  • knowing how to provide the API with API tokens
  • knowing which HTTP verbs are used
  • knowing which mime-types are used
  • specifying the consumer-token and user-agent
  • common experience between unknown and well-known services

The following is a rough sketch of what usage might look like:

resp, err := client.Unstructured.Create(endpoint, json-marshallable-params, &result) # unmarshall to result
resp, err := client.Unstructured.Delete(endpoint)
resp, err := client.Unstructured.Update(endpoint, json-marshallable-params, &result)

resp, err := client.Unstructured.List(endpoint, json-marshallable-params, &listOpts, &result) # result must be a slice
resp, err := client.Unstructured.ListWithPagination(endpoint, json-marshallable-params, &listOpts, &result)
# List with pagination is more common, so perhaps List and ListWithoutPagination are offered

bytes, resp, err := client.Unstructured.Get(endpoint, path, &obj, &getOpts)

client.Unstructuted.Href(&object) # return the href via reflection? Is there any need for this?

Can a pattern like this be used as the base for typed services?

displague avatar Nov 18 '20 19:11 displague