From 8d1e0c352095263f22027adfe6e986903cad6fc5 Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 20 Nov 2022 18:03:46 +0100 Subject: [PATCH] docs: change api response format from objects to arrays a possibly better data format to work with in javascript. --- README.md | 84 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index b2c3c28..c1d5c5b 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,39 @@ such proxies to reduce IP address leaks and client fingerprinting. ## API v1 -there's a single endpoint accepting a nostr event id and relay to fetch the event from: +over HTTP, noxy exposes a single endpoint accepting a nostr event id and +a relay to fetch the event from: GET /api/v1/e/?relay= +the response is an array of objects: + +```json +[ + { + "url": "", + "cache": "", + "kind": "media|preview", + "size": 123, + "title": "resource title", + "descr": "resource description" + } +] +``` + +where `url` is the original url found in a nostr event payload and `cache` is the +proxied url or a link preview image. the other fields presence and their values +depend on the `kind` of the resource. + +for images, videos and audio the `kind` field is `media` and the `size` is the +file size in bytes as stored in cache. if the file size is unknown at the time +of a response, it is 0. + +for link previews, the `kind` field is `preview`, `cache` url points to a link +preview image and the `size` is the preview image size. link preview image, +`title` and `descr` field values are collected using +[the open graph protocol](https://ogp.me/) or [oEmbed](https://oembed.com/). + some examples follow. ### fetch a pubkey profile picture, event kind 0 @@ -22,21 +51,22 @@ request example: response: ```json -{ - "images": { - "https://git.qcode.ch/avatars/5a8071777eba7ebf178143fa650c8012?size=870": "https://noxy.example.org/abcdef/abcdef0123456789.png" +[ + { + "url": "https://git.qcode.ch/avatars/5a8071777eba7ebf178143fa650c8012?size=870", + "cache": "https://noxy.example.org/abcdef/abcdef0123456789.png", + "kind": "media", + "size": 279342 } -} +] ``` [event raw data →](https://nostr.com/e/e01ac1cfc5cb68b54183f878261b21ef30a65f5e06a24356cfe3ecdacce14bae) -if a noxy instance is unable to fetch the original, it responds with an empty object: +if a noxy instance is unable to fetch the original, it responds with an empty array: ```json -{ - "images": {} -} +[] ``` ### fetch images from a text note, event kind 1 @@ -48,11 +78,14 @@ request example: response: ```json -{ - "images": { - "https://res.cloudinary.com/eskema/image/upload/v1668636521/osso_vt7qh7.png": "https://noxy.example.org/fedcba/fedcba9876543210.png" +[ + { + "url": "https://res.cloudinary.com/eskema/image/upload/v1668636521/osso_vt7qh7.png", + "cache": "https://noxy.example.org/fedcba/fedcba9876543210.png", + "kind": "media", + "size": 93241 } -} +] ``` [event raw data →](https://nostr.com/e/d822fdd220d8a74d2f025f331840eec8a640a663f1d3ca3de9f6a74ff0cc61fa) @@ -66,23 +99,16 @@ request example: response: ```json -{ - "links": { - "https://github.com/fiatjaf/noscl/pull/24": { - "og:image": "https://opengraph.githubassets.com/dc27...92c8/fiatjaf/noscl/pull/24", - "og:image:alt": "if the arg to publish or message command is '-', it is read from stdin.\ncloses #19", - "og:image:width": "1200", - "og:image:height": "600", - "og:site_name": "GitHub", - "og:type": "object", - "og:title": "publish,message: accept content from stdin by x1ddos · Pull Request #24 · fiatjaf/noscl", - "og:description": "if the arg to publish or message command is '-', it is read from stdin.\ncloses #19" - } - }, - "images": { - "https://opengraph.githubassets.com/dc27...92c8/fiatjaf/noscl/pull/24": "https://noxy.example.org/beef01/beef0123456789.png" +[ + { + "url": "https://github.com/fiatjaf/noscl/pull/24", + "cache": "https://noxy.example.org/beef01/beef0123456789.png", + "kind": "preview", + "size": 110480, + "title": "publish,message: accept content from stdin by x1ddos · Pull Request #24 · fiatjaf/noscl", + "descr": "if the arg to publish or message command is '-', it is read from stdin.\ncloses #19" } -} +] ``` [event raw data →](https://nostr.com/e/af30dac1d800acc25b87d0d6d0dd33bddf49e7f356556540a6c7722e3cb363fe) -- 2.46.2