View all our code samples

Using go-resty in Go

Go-Resty is a third-party HTTP client library for GoLang. It provides an easy-to-use API for making HTTP requests and handling responses, similar to libraries like net/http. Go-Resty simplifies tasks such as setting headers, handling cookies, and managing request parameters.

We've implemented a code sample that you can re-use to convert your HTML documents to PDF, JPG, PNG or WEBP using PDFShift and Go:

package main

import (

// Convert function makes a POST request to the provided endpoint with the supplied parameters
func convert(apiKey string, params map[string]string, endpoint string) ([]byte, error) {
    client := resty.New()

    resp, err := client.R().
        SetBasicAuth("api", apiKey).
        SetHeader("Content-Type", "application/json").
        Post(fmt.Sprintf("", endpoint))

    if err != nil {
        return nil, err

    if _, ok := params["filename"]; ok || params["webhook"]; ok {
        var response map[string]interface{}
        err := json.Unmarshal(resp.Body(), &response)
        if err != nil {
            return nil, err
        return json.Marshal(response)

    return resp.Body(), nil

Here's how you can use the above code:

func main() {
    params := map[string]string{"source": ""}
    apiKey := "sk_XXXXXXXXXXXXXX"

    resp, err := convert(apiKey, params, "pdf")
    if err != nil {

    error := ioutil.WriteFile("result.pdf", resp, 0644)
    if error != nil {

We've tested this code with the latest version of go-resty and it's ready to be used in your project.

But if you were to encounter any bugs or issues while running it (or if you want to suggest changes to improve the code), please contact us and we'll be happy to help you out.