-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add recursive directory and make all endpoints JSON #2493
Conversation
I didn't review the code, since we're still discussing the best way to do this. There's another way we could do this, which is to serve all recursive endpoints under So Then, recursive inscriptions could fetch recursive API endpoints with relative paths. For example, with a recursive inscription served at
This works because relative paths are interpreted by appending the relative path to the current URL with anything after the last slash removed. The relative path This has the advantage of having shorter URLS in inscriptions, since they can request |
What are the reasons for selecting
General direction, yes. I think it is the right move to separate out inscription IDs with general API functions. I have no issues with using absolute paths which I think is an accepted convention for web.
If single path is a concern, then how about better namespacing? Example with 3-letter abbreviation, but I imagine you could select much better formats to maximize for other values such as relative paths:
In terms of character count, its the same as More food for thought If the URL is too long in general, it might make sense to solve this issue separately. Ex, one can hide the URL lengths with a small JS SDK with short function names. This way devs can fetch API functions and inscriptions with less focus on URL length. Ex, <script src="/content/[id-to-js-sdk].js" />
<script>
const { ord } = window;
ord.ins([content-id]);
ord.api([function-name]);
</script> |
For inscriptions every byte matters, so I like paths that are as short as possible. @casey's relative path sounds good for keeping the endpoints very short. Endpoints should also be as easy as possible to support for explorers. Having an endpoint that returns the full list of inscriptions at a given sat may not scale well when there are thousands of inscriptions on a given sat at some point in the future. Pagination/offset may be needed. |
Currently I got #2452
I just saw this comment #2277 (comment) I will take out 1. Change to?
agreed I think that is a good way to do it as well. To get the most recent inscription on a sat const recentId = await fetch("/sat/69420/-1");
console.log(recentId.id)
Yeah that is why I have
Something to consider for that is make a shorter inscriptionId based on block and index. See #2489 Question: Will we be able to resolve |
Yes, and that it is not used by anything else.
Yes, the CSP header allows requests to all paths underneath.
At the moment I'm not too concerned about this but the @casey's approach is very elegant although it makes caching a bit more difficult since we now have dynamic content under
The only weird thing would be that some would return binary data + MIME type and others JSON. |
+1 on name-spacing. Not sold on using Around the same topic should consider introducing a namespace for all the non-recursive endpoints too, especially for APIs. Maybe, even add a version prefix: Re: the approach proposed by @casey - I think the space savings by that would be miniscule and we risk making inscriptions brittle as relative paths would break when those inscriptions are loaded from other namespaces (i.e |
If
Do we think its a good idea to save on bytes by using shorter notations? That wouldn't be as clear for new people learning the endpoints without referencing the mapping and could cause collisions in future if a endpoint has similar spelling.
I am gonna reference the old recursion discussion because we originally had it |
I believe the caching issues are due to the same endpoint (i.e /content/sat/1234/-1) possibly returning different content based on what's been inscribed, making it harder to cache without a more complex cache invalidation method. So, |
Get the neosporin out |
Maybe they can be a sponsor |
Just thinking out loud here: Would it be a bad idea to have two sets of endpoints with the same functionality? One human readable for the inscriptions that aren't sensitive to bytes. Link shortened version for byte sensitive inscriptions. Most of the inscriptions I've seen don't have too many references to the URL and ones with many are often interpolating the URL path via a loop. // Seen this a lot for many recursive inscriptions
let url = "/content/" + i Personally, not really convinced 1-character URL path prefixes really make a huge difference in the examples I have seen so far. |
Another option is to make future recursive endpoints all single characters. This would make them very short, and set them apart from and avoid conflict with non-recursive endpoints. |
I love it, it looks like /-/ will be my preferred method. Trying to consider all the avenues of future proofing and how everything on the roadmap might affect these endpoints going forward so we can avoid any future changes. |
@casey We would still have to add all these to CSP headers by having /-/ we would only have to do one. Lets say we add even more like TX or output/input. We could run into collisions eventually.
idk if we would add all these just trying to think of some more. |
I don't think we should be returing the json of the inscription id on the |
Look at this PR everything is to be Json going forward we are extending the prior block ones to be json.
They would be set in stone In addition ordinals.com might not ever do that but other explorers are more than welcome to add all these keys. If we standardize to JSON then other explorers could do things first and then ordinals could eventually support it if it becomes popular. You can make as many endpoints as you want and run your own explorers nobody should live and die by this repo. However coming together and standardizing things is important. |
Summary+ Pros
- Cons Everything in JSON for future recursion PaginationExample /children and /sat routes with multiple inscriptions Option A: 1 inscription at a time. + Simple, Smaller request size
- requires more requests for many inscriptions, Doesn't have 0 index Option B: 10-100 inscriptions at a time + Returns more inscriptions per request
- Needs params `offset` `reverse` bigger request size, Requires more code to work with array. RoutingOption 1: Recursive Directory under /-/ Example: /-/sat/<SAT>/<Index>
+ One CSP header, Easier caching
- Extra bytes. Option 2: Recursive Directory under /content/ Example: /content/blocktime would only need fetch(blocktime)
+ Shorter URLs, Relative paths
- Caching issues Option 3: Single Character Endpoints /Letter Example: /s for sat, /h for blockheight.
+ Shorter URLs, No collision with html routes
- Letter collisions. multiple CSP headers. Option 4: Single Character Endpoints under /content/ Example: /content/s
+ Shortest possible bytes, 1 CSP header, Relative path.
- Letter collisions. Caching issues. Option 5: Single Charcter Endpoints under /-/ Example: /-/s
+ 1 CSP header, segregated routes, Short route names, Easier caching
- Letter collisions, Extra bytes for /-/ Option 6: Single Character Endpoints under /0/ versioned Example: /0/s
+ Shortest possible bytes, Relative path, Version controlled
- Letter collisions, Needs extra CSP headers each version Option 7: Single Charcter Endpoints under /0/ version full name Example: /0/sat
+ 1 CSP header, segregated routes, Easier caching, Version controlled
- Extra bytes for /0/ and full name, Needs extra CSP headers each version |
An option other than |
I like this a lot. Should make maintaining things in the future a lot cleaner. |
Great idea on the versioning. You can even use |
One thing to keep in mind here is that if we have the same inscriptions accessible via different routes, it could break inscriptions that rely on fetching inscription ID from the URL. I have advocated for having inscription content accessible via indexed routes (i.e |
I updated summary with the two new options. @casey wouldn't the version need new CSP headers each time we add a new version? |
I think we should just go with /-/ like this PR is initially shows. Would adding new keys to the response break any inscription prior? Because they won't be aware of any new keys we add say if we add rarity to the sat endpoint it won't break any inscriptions from my understanding. The current sat endpoint PR is using /-/ so people can build that branch and play around with it in regtest. |
Love seeing all the debate here. It's very hard to choose between the different options for me. I think they're all good and unlock huge value for Ordinals. Would err on the side of whichever gives the most optionality for the future. |
We went with |
In order to avoid future clashes with other normal endpoints all future recursive endpoints should be under
/-/
. I copied the existing ones here as well and made sure they all return valid JSON. The existing ones will stay where they are for backwards compatability. Also the/content/<INSCRIPTION_ID>
stays where it is.Tagging everything relevant:
#2476
#2277
#2431
#2452
@elocremarc, @devords, @huuep, @casey, @veryordinally, @stet, @BitTogether, @tansanDOTeth and @rot13maxi what do you think? Is this the right way to proceed?
For example, future endpoints like the sat one would be:
/-/sat/<SAT>
and return JSON with a list of inscriptions on that sat.