api

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package api provides an HTTP client for the Memegen.link API.

Index

Constants

View Source
const DefaultBaseURL = "https://api.memegen.link"

DefaultBaseURL is the Memegen.link API base URL.

Variables

This section is empty.

Functions

func AppendQueryParams

func AppendQueryParams(baseURL string, params url.Values) (string, error)

AppendQueryParams merges the given url.Values onto baseURL's existing query string. It is used to add presentation params (color, width, etc.) to the meme URL returned by the API.

func WithClient

func WithClient(ctx context.Context, cl *Client) context.Context

WithClient stores a Client in the context.

Types

type AutomaticRequest

type AutomaticRequest struct {
	Text string `json:"text"`
	Safe bool   `json:"safe"`
}

AutomaticRequest is the payload for POST /images/automatic.

type AutomaticResponse

type AutomaticResponse struct {
	URL        string  `json:"url"`
	Generator  string  `json:"generator,omitempty"`
	Confidence float64 `json:"confidence,omitempty"`
}

AutomaticResponse is the response from POST /images/automatic.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client wraps an HTTP client for Memegen API calls.

func ClientFromContext

func ClientFromContext(ctx context.Context) *Client

ClientFromContext retrieves the Client from the context.

func NewClient

func NewClient(opts ClientOptions) *Client

NewClient builds a Client with retry transport and optional verbose logging.

func (*Client) Generate

func (c *Client) Generate(ctx context.Context, req GenerateRequest) (*GenerateResponse, error)

Generate posts a template-based meme request to POST /images and returns the generated meme URL.

func (*Client) GenerateAutomatic

func (c *Client) GenerateAutomatic(ctx context.Context, req AutomaticRequest) (*AutomaticResponse, error)

GenerateAutomatic posts text to /images/automatic and returns the auto-selected meme URL along with generator metadata.

func (*Client) GenerateCustom

func (c *Client) GenerateCustom(ctx context.Context, req CustomRequest) (*GenerateResponse, error)

GenerateCustom posts a custom-background meme request to POST /images/custom and returns the generated meme URL.

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string) (*http.Response, error)

Get performs a GET request against the API.

func (*Client) GetFont

func (c *Client) GetFont(ctx context.Context, id string) (*Font, error)

GetFont fetches a single font by ID from GET /fonts/{id}.

func (*Client) GetTemplate

func (c *Client) GetTemplate(ctx context.Context, id string) (*Template, error)

GetTemplate fetches a single template by ID from GET /templates/{id}.

func (*Client) ListFonts

func (c *Client) ListFonts(ctx context.Context) ([]Font, error)

ListFonts fetches all fonts from GET /fonts.

func (*Client) ListTemplates

func (c *Client) ListTemplates(ctx context.Context, filter string) ([]Template, error)

ListTemplates fetches all meme templates from GET /templates. The optional filter query-param narrows results server-side.

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, body io.Reader) (*http.Response, error)

Post performs a POST request against the API with a JSON body.

type ClientOptions

type ClientOptions struct {
	BaseURL   string
	APIKey    string
	Verbose   bool
	UserAgent string
}

ClientOptions configures a new Client.

type CustomRequest

type CustomRequest struct {
	Background string   `json:"background"`
	Text       []string `json:"text"`
	Extension  string   `json:"extension,omitempty"`
	Font       string   `json:"font,omitempty"`
	Layout     string   `json:"layout,omitempty"`
	Style      string   `json:"style,omitempty"`
	Redirect   bool     `json:"redirect"` // always false
}

CustomRequest is the payload for POST /images/custom.

type Error

type Error struct {
	StatusCode int
	Message    string
}

Error represents an error from the Memegen API.

func (*Error) Error

func (e *Error) Error() string

type Font

type Font struct {
	ID       string  `json:"id"`
	Alias    *string `json:"alias"` // nullable in API
	Filename string  `json:"filename"`
	Self     string  `json:"_self"`
}

Font describes a font from the API.

type GenerateRequest

type GenerateRequest struct {
	TemplateID string   `json:"template_id"`
	Text       []string `json:"text"`
	Extension  string   `json:"extension,omitempty"`
	Font       string   `json:"font,omitempty"`
	Layout     string   `json:"layout,omitempty"`
	Style      []string `json:"style,omitempty"`
	Redirect   bool     `json:"redirect"` // always false
}

GenerateRequest is the payload for POST /images/{template_id}.

type GenerateResponse

type GenerateResponse struct {
	URL string `json:"url"`
}

GenerateResponse is the response from template/custom generation endpoints.

type Template

type Template struct {
	ID       string   `json:"id"`
	Name     string   `json:"name"`
	Lines    int      `json:"lines"`
	Overlays int      `json:"overlays"`
	Styles   []string `json:"styles"`
	Blank    string   `json:"blank"`
	Example  struct {
		Text []string `json:"text"`
		URL  string   `json:"url"`
	} `json:"example"`
	Source   string   `json:"source"`
	Keywords []string `json:"keywords"`
	Self     string   `json:"_self"`
}

Template describes a meme template from the API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL