# README

session package

This library provides a simple and consistent REST over HTTP library for accessing Akamai Endpoints

Depedencies

This library is dependent on the github.com/akamai/AkamaiOPEN-edgegrid-golang/pkg/edgegrid interface.

Basic Example

func main() {
     edgerc := Must(New())

     s, err := session.New(
         session.WithConfig(edgerc),
     )
     if err != nil {
         panic(err)
     }

     var contracts struct {
		AccountID string         `json:"accountId"`
		Contracts ContractsItems `json:"contracts"`
        Items []struct {
            ContractID       string `json:"contractId"`
		    ContractTypeName string `json:"contractTypeName"`
        } `json:"items"`
     }

     req, _ := http.NewRequest(http.MethodGet, "/papi/v1/contracts", nil)

     _, err := s.Exec(r, &contracts)
     if err != nil {
         panic(err);
     }

     // do something with contracts
}
        

Library Logging

The session package supports the structured logging interface from github.com/apex. These can be applied globally to the session or to the request context.

Adding a logger to the session

    s, err := session.New(
         session.WithConfig(edgerc),
         session.WithLog(log.Log),
     )
     if err != nil {
         panic(err)
     }

Request logging

The logger can be overidden for a specific request like this

    req, _ := http.NewRequest(http.MethodGet, "/papi/v1/contracts", nil)

    req = req.WithContext(
        session.ContextWithOptions(request.Context(),
            session.WithContextLog(otherlog),
        )

Custom request headers

The context can also be updated to pass special http headers when necessary

    customHeader := make(http.Header)
    customHeader.Set("X-Custom-Header", "some custom value")

    req = req.WithContext(
        session.ContextWithOptions(request.Context(),
            session.WithContextHeaders(customHeader),
        )

# Functions

ContextWithOptions adds request specific options to the context This log will debug the request only using the provided log.
Must is a helper tthat will result in a panic if an error is returned ex.
New returns a new session.
WithClient creates a client using the specified http.Client.
WithContextHeaders sets the context headers.
WithContextLog provides a context specific logger.
WithHTTPTracing sets the request and response dump for debugging.
WithLog sets the log interface for the client.
WithSigner sets the request signer for the session.
WithUserAgent sets the user agent string for the client.

# Constants

Version is the client version.

# Variables

ErrInvalidArgument is returned when invalid number of arguments were supplied to a function.
ErrMarshaling represents marshaling error.
ErrUnmarshaling represents unmarshaling error.

# Interfaces

No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author