Code samples

Code samples to get you started quickly with Ruby, Python, PHP and Node.js.

Ruby (using standard library)

This Ruby example creates creates a new PDF job. It reads the API key from the PAPERPLANE_API_KEY environment variable, so make sure you have that configured.

require "uri"
require "net/http"

endpoint = URI.parse("https://api.paperplane.app/jobs")
http = Net::HTTP.new(endpoint.host, endpoint.port)
http.use_ssl = true

request = Net::HTTP::Post.new(endpoint.request_uri)
request.basic_auth(ENV.fetch("PAPERPLANE_API_KEY"), "")
request.set_form_data(
  "url" => "https://en.wikipedia.org/wiki/Airplane",
  "page_size" => "A4"
)

response = http.request(request)
puts response.body

Ruby (using the HTTP gem)

This Ruby example uses the HTTP gem which provides a more convenient API than the standard library packages.

Python

This Python example creates creates a new PDF job. It reads the API key from the PAPERPLANE_API_KEY environment variable, so make sure you have that configured.

The requests library is used for making HTTP requests, so you'll need to have that installed.

PHP

This example creates creates a new PDF job. It reads the API key from the PAPERPLANE_API_KEY environment variable, so make sure you have that configured.

Node.js

This snippet creates creates a new PDF job. It reads the API key from the PAPERPLANE_API_KEY environment variable, so make sure you have that configured.

This example uses the node-fetch library for making HTTP requests.

Java

This snippet creates creates a new PDF job. It reads the API key from the PAPERPLANE_API_KEY environment variable, so make sure you have that configured.

This example uses the Apache HttpComponents library for making HTTP requests.

C# (.NET Core)

Go

This snippet creates creates a new PDF job. It reads the API key from the PAPERPLANE_API_KEY environment variable, so make sure you have that configured.

Other languages

We will gradually be adding examples for other languages here. If there’s a specific language you’d like an example for, please get in touch and let us know.

Last updated