ExUrlbox (ExUrlbox v0.3.0)
View SourceA light wrapper for the Urlbox API.
Compatible with Urlbox API Version: v1
A list of options that you can pass into ExUrlbox.get/3
, ExUrlbox.post/3
, ExUrlbox.head/3
, and ExUrlbox.delete/3
can be found here:
https://urlbox.io/docs/options
Summary
Functions
Urlbox will cache previously created screenshots for some time. Sending a delete request removes a previously created screenshot from the cache.
Send a request to Urlbox for a screenshot. Refer to the official documentation for all the available options: https://urlbox.io/docs/options
If you just want to get the response status/headers without pulling down the full response body.
Post a request to Urlbox for a screenshot.
You should provide a webhook_url
option to receive a postback to once the screenshot render is complete.
Functions
@spec delete(String.t(), list(), integer()) :: {:error, any()} | {:ok, Tesla.Env.t()}
Urlbox will cache previously created screenshots for some time. Sending a delete request removes a previously created screenshot from the cache.
- Example request:
ExUrlbox.delete("https://anthonymineo.com")
@spec get(String.t(), list(), integer()) :: {:error, any()} | {:ok, Tesla.Env.t()}
Send a request to Urlbox for a screenshot. Refer to the official documentation for all the available options: https://urlbox.io/docs/options
This action is synchronous
.
If you want to use an async
flow that uses webhooks, use ExUrlbox.post/3
.
Function signature is: url, [options], timeout
Example request:
ExUrlbox.get("https://anthonymineo.com")
Example with options:
ExUrlbox.get("https://anthonymineo.com", [format: "png", full_page: true])
Example with timeout (5s):
ExUrlbox.get("https://anthonymineo.com", [], 5_000)
@spec head(String.t(), list(), integer()) :: {:error, any()} | {:ok, Tesla.Env.t()}
If you just want to get the response status/headers without pulling down the full response body.
- Example request:
ExUrlbox.head("https://anthonymineo.com")
@spec post(String.t(), list(), integer()) :: {:error, any()} | {:ok, Tesla.Env.t()}
Post a request to Urlbox for a screenshot.
You should provide a webhook_url
option to receive a postback to once the screenshot render is complete.
This action is async
.
Example request with options containing
webhook_url
for a postback:ExUrlbox.post("https://anthonymineo.com", [webhook_url: "https://app-waiting-for-incoming-post.com/"])
Initial response from a post:
{ "renderId": "ebcbce5q-9657-435f-aeb6-5db207ee87b5", "status": "created", "statusUrl": "https://api.urlbox.io/render/ebcbce5q-9657-435f-aeb6-5db207ee87b5" }
If you dont provide a
webhook_url
you will need to poll thestatusUrl
for the status of your request:{ "renderId": "ebcbce5q-9657-435f-aeb6-5db207ee87b5", "status": "succeeded", "renderUrl": "https://renders.urlbox.io/urlbox1/renders/a1d7g7d45f7am5a0a69cd3de/2022/5/7/ebcbce5q-9657-435f-aeb6-5db207ee87b5.png", "size": 34748 }
Example of a postback to
webhook_url
:{ "event": "render.succeeded", "renderId": "ebcbce5q-9657-435f-aeb6-5db207ee87b5", "result": { "renderUrl": "https://renders.urlbox.io/urlbox1/renders/a1d7g7d45f7am5a0a69cd3de/2022/5/7/ebcbce5q-9657-435f-aeb6-5db207ee87b5.png", "size": 34748 }, "meta": { "startTime":"2022-05-07T20:25:28.879Z", "endTime":"2022-05-07T20:25:31.646Z" } }