Example Implementation
This page was copied from https://github.com/Conshax/OCPS/blob/main/example-implementation.md with the permission of Conshax.
Disclaimer
The Postman desktop app currently crashes on responses with a binary in the body (see this issue). We recommend to use the web app or our curl examples for testing.
Test Podcast
We have created a test podcast, "The OCPS Show", for testing and prototyping purposes that contains one episode. This episode's audio file behaves adherent to the OCPS.
{% tabs %} {% tab title="Test Podcast" %} Name: "The OCPS Show"
Link: https://podcastindex.org/podcast/6004846
Feed URL: https://podcasts-public.s3.eu-central-1.amazonaws.com/a3a1b651-94e2-56f0-9dee-a23813aa7220/feed.rss
Episode audio URL: https://lsat-test.conshax.app/podcast/a3a1b651-94e2-56f0-9dee-a23813aa7220/episode/lsat-test.mp3
Episode Length: 03:30 / 10:54 (free / full)
Episode GUID: a3a1b651-94e2-56f0-9dee-a23813aa7220
{% endtab %} {% endtabs %}
Test episode behavior
The first 03:30 minutes of the episode are available for free
Download request:
No LSAT support: 03:30 minutes are downloaded
LSAT support: server responds with status 402 "payment required" and the necessary payment information
Streaming request:
No LSAT support: client can stream 03:30 minutes, then the episode is "finished"
LSAT support: client can stream 03:30 minutes, then the the server responds with 402 "payment required" and the necessary payment information
Interacting with the test episode
Query file information
{% swagger method="head" path=" " baseUrl="{episode audio url} " summary="Retrieve file meta data" %} {% swagger-description %} Query HTTP headers to learn meta data about the file, e.g., the file size. {% endswagger-description %}
{% swagger-parameter in="header" name="X-Accept-Authenticate" %} lsat-keysend (optional) {% endswagger-parameter %}
{% swagger-response status="200: OK" description="" %} {% tabs %} {% tab title="Without header" %}
The Accept-Ranges
header indicates that the client can request parts of the resource with custom byte ranges. {% endtab %}
{% tab title="With header" %}
The Lsat-Free-Content-Length
header specifies the maximum number of bytes that can be requested without payment.
The WWW-Authenticate
header contains the information for the payment required to access the full resource.
{% endtab %} {% endtabs %} {% endswagger-response %} {% endswagger %}
Make a valid keysend payment
For testing purposes, it is sufficient to pay the recipient returned in the 402 response. The SATS you send during testing go to our node, we'll happily return them to you if you contact us.
Make sure the keysend payment contains the following data in the custom records:
If you can't or don't want to make the keysend payment, you can use this preimage for testing:
3630626264383464316435666130356136653430616139386337663331643365
Download the episode audio
Client with no LSAT support:
{% swagger method="get" path=" " baseUrl="{episode audio url}" summary="Download request (no LSAT)" expanded="false" %} {% swagger-description %}
{% endswagger-description %}
{% swagger-response status="200: OK" description="Audio file" %}
{% endswagger-response %} {% endswagger %}
Client with LSAT support:
{% swagger method="get" path=" " baseUrl="{episode audio url}" summary="Download request before payment" expanded="false" %} {% swagger-description %} LSAT support is communicated by setting either the header OR the query parameter.
Hint: Keep in mind that query parameters are case sensitive. {% endswagger-description %}
{% swagger-parameter in="query" name="lsat-accept-authenticate" type="" %} lsat-keysend {% endswagger-parameter %}
{% swagger-parameter in="header" name="X-Accept-Authenticate" type="" %} lsat-keysend {% endswagger-parameter %}
{% swagger-response status="402: Payment Required" description="Payment required" %} The payment information can be retrieved from the body or the WWW-Authenticate
header:
{% endswagger-response %} {% endswagger %}
{% swagger method="get" path=" " baseUrl="{episode audio url}" summary="Download request after payment" expanded="false" %} {% swagger-description %} The token (provided by the server in the 402 return) and the hex encoded payment preimage can be set via header OR query parameter.
Hint: Keep in mind that query parameters are case sensitive and must be URL encoded. {% endswagger-description %}
{% swagger-parameter in="query" name="lsat-authorization" type="" %} <token:preimage> (URL encoded) {% endswagger-parameter %}
{% swagger-parameter in="header" name="Authorization" type="" %} <token:preimage> {% endswagger-parameter %}
{% swagger-response status="200: OK" description="Audio file" %}
{% endswagger-response %}
{% swagger-response status="400: Bad Request" description="Bad request" %} Server responds with 400 as well as an error description and the payment information in the body:
{% endswagger-response %} {% endswagger %}
Stream the episode audio
Client with no LSAT support:
{% swagger method="get" path=" " baseUrl="{episode audio url}" summary="Stream request (no LSAT)" expanded="false" %} {% swagger-description %}
{% endswagger-description %}
{% swagger-parameter in="header" name="Range" required="true" %} e.g.: bytes=0-40000 {% endswagger-parameter %}
{% swagger-response status="206: Partial Content" description="Partial audio file" %}
{% endswagger-response %} {% endswagger %}
Client with LSAT support:
{% swagger method="get" path=" " baseUrl="{episode audio url}" summary="Stream request before payment" expanded="false" %} {% swagger-description %} LSAT support is communicated by setting either the header OR the query parameter.
Hint: Keep in mind that query parameters are case sensitive. {% endswagger-description %}
{% swagger-parameter in="query" name="lsat-accept-authenticate" type="" %} lsat-keysend {% endswagger-parameter %}
{% swagger-parameter in="header" name="X-Accept-Authenticate" type="" %} lsat-keysend {% endswagger-parameter %}
{% swagger-parameter in="header" name="Range" required="true" %} e.g.: bytes=0-40000 {% endswagger-parameter %}
{% swagger-response status="206: Partial Content" description="Partial audio file" %} Requested byte range is freely available:
{% endswagger-response %}
{% swagger-response status="402: Payment Required" description="Payment required" %} Requested byte range is protected.
The payment information can be retrieved from the body or the WWW-Authenticate
header:
{% endswagger-response %} {% endswagger %}
{% swagger method="get" path=" " baseUrl="{episode audio url}" summary="Stream request after payment" expanded="false" %} {% swagger-description %} The token (provided by the server in the 402 return) and the hex encoded payment preimage can be set via header OR query parameter.
Hint: Keep in mind that query parameters are case sensitive and must be URL encoded. {% endswagger-description %}
{% swagger-parameter in="query" name="Lsat-Authorization" type="" %} <token:preimage> (URL encoded) {% endswagger-parameter %}
{% swagger-parameter in="header" name="Authorization" type="" %} <token:preimage> {% endswagger-parameter %}
{% swagger-parameter in="header" name="Range" required="true" %} e.g.: bytes=550001-560000 {% endswagger-parameter %}
{% swagger-response status="206: Partial Content" description="Partial audio file" %}
{% endswagger-response %}
{% swagger-response status="400: Bad Request" description="Bad request" %} Server responds with 400 as well as an error description and the payment information in the body:
{% endswagger-response %} {% endswagger %}
Full interaction examples (Shell / Curl)
{% tabs %} {% tab title="No LSAT support" %}
{% endtab %}
{% tab title="LSAT via headers" %}
{% endtab %}
{% tab title="LSAT via query parameters" %}
{% endtab %} {% endtabs %}
Last updated