• Activity
  • Votes
  • Comments
  • New
  • All activity
  • Showing only topics with the tag "api". Back to normal view
    1. Ask Tildes: Design practices for retrieving dozens (or hundreds) of related records over a RESTful API

      I'm looking for some feedback on a feasible mechanism for structuring a few API endpoints where a purely RFC-spec compliant REST API wouldn't suffice. I have an endpoint which returns $child...

      I'm looking for some feedback on a feasible mechanism for structuring a few API endpoints where a purely RFC-spec compliant REST API wouldn't suffice.

      I have an endpoint which returns $child entries for a $parent resource, let's call it: /api/parent/:parentId/children. There could be anywhere from a dozen to several hundred children returned from this call. From here, a child entity is related to a single userOrganization, which itself is a pivoting entity on a single user. The relationship between a child and user is not strictly transitive, but can each child only has one userOrganization which only has one user, so it is trivial to reach a user from a child resource.

      Given this, the data I need for the particular request involves retrieving all user's for a parent. The obvious, and incorrect solution to the problem is to make the request mentioned above, and then iterate through and make an API request to retrieve each user. This is less than very good as this would obviously be up to several hundred API calls.

      There's a few more scalable solutions that could solve this problem, so any input on these ideas is great; but if you have a better proposal that also works, I'm keen to explore that!

      Include user relationships in the call by default.

      This certainly does solve the problem, but it's also pumping down a load of data I don't necessarily need. This would probably 2x the amount of bytes travelling along the wire, and in 8 out of 10 calls, that extra data isn't needed.

      Have a separate /api/parent/:parentId/users call.

      Another option that partially solves the issue: I need data from both the child and the user to format this view, so I'd still need to make the initial call I documented earlier. Semantically, it feels a bit odd to have this as a resource because I don't consider a user to be nested under a parent in terms of database topology.

      Keep the original call, but add a query parameter to fetch the extra data

      This comes across as the 'least worst' idea objectively, in terms of flexibility and design. Through the addition of the query parameter, you could optionally retrieve the relationship's data. This seems brittle and doesn't scale well to other endpoints where it could be useful though.

      Utilize a Stripe expands-style query parameter.

      Stripe implements the ability to retrieve all related records from an API endpoint by specifying the relations as strings. This is essentially the same as the above answer, but is scaled to all available API endpoints. I love this idea, but implementing it in a secure way seems fraught with disaster. For example, this is a multi-tenancied application, and it would be trivial to request userOrganization.user.organizations.users. This would retrieve all other organisations for the user, and their users! This is because my implementation of expands simply utilises the ORM of my choice to perform a database join, and of course the database has no knowledge about application tenancy!


      Now, I do realise this problem could easily be solved by implementing a GraphQL API server, which I have done in the past, but unfortunately time and workload constraints dictate implementing a GraphQL-based solution is infeasible. As much as I like GraphQL, I'm not as proficient in that area as compared to implementing high quality traditional APIs, and the applications I'm working on at the moment are focusing on choosing boring technology, and not using excessive innovation tokens.

      Furthermore, I do consider the conceptuals around REST APIs to be more of an aspirational sliding scale, rather than a well defined physical entity, because let's face it, the majority of popular APIs today aren't REST-compliant, even Stripe's isn't, and it's usually both financially healthier and feature-rich to choose a development path that results in a rough product that can be refined later, than aiming for a perfect initial release. All this said, I don't mind proposals or solutions to my problem that are "good enough". As long as they aren't too hacky! :)

      10 votes
    2. Reddit's redesign has been down all day, however mobile apps work, and old reddit works. Does reddit not use the same public API for the redesign?

      I'm not sure if this is the case for everyone but the new reddit can't load any data, at least for me. However, old.reddit.com works, and all mobile apps seem to work which obviously use the...

      I'm not sure if this is the case for everyone but the new reddit can't load any data, at least for me. However, old.reddit.com works, and all mobile apps seem to work which obviously use the reddit API. I am curious, does reddit have a different version of their API for the redesign, and that's what's been down for hours?

      edit: I know that reddit must allow their own product to do things that other products don't.. Like it seems the chat api is not open to 3rd parties.. but I assumed that they would have just blocked certain api endpoints from public exposure. But based on my blind troubleshooting of this case, it seems that they must be using a totally different interface all together for the redesign?


      edit2: Copy paste of my down-thread comment in case you don't read the whole thread, the context is that I realize that this must not be a global issue.

      Hmm, so I've heard reddit is super-cached... is this possibly a caching fault then?

      reddit uses redis, correct? And it must be sharded, right? So maybe some redis cluster nodes are down?

      I'm trying to learn here, and I am likely asking the wrong questions.. The goal of my post was to understand this type of failure, as I realize that it must be partial as in if all of reddit resign was down, it would be news. If anyone could correct any of my statements or assumptions I would really appreciate it.

      13 votes
    3. Request: API to fetch all comments including hierarchy relationship

      Hello, I saw in another thread being mentioned that there is no use for API for real users other than bots. So wanted to voice some real API uses that I would be interested in: When I post a new...

      Hello,

      I saw in another thread being mentioned that there is no use for API for real users other than bots. So wanted to voice some real API uses that I would be interested in:

      1. When I post a new blog post, if I find it worthy of sharing here, it would be nice to mirror the comments I get here back on my blog post. I can imagine using API to fetch all the comments from a tildes thread, including the hierarchy relationship. The API would return a JSON with Markdown and/or HTML like the XML that Disqus exports (but JSON). When people want to comment on that post, they can come to tildes to do so, or if they don't want to create an account here, or if they don't have an invite, they can comment via other means that I have (Webmentions, Twitter, email).
      2. Second use is make something like hnrss possible.
      4 votes
    4. Source and API

      If it's too early in development for these questions, let me know. Is the source available yet? If so, where is it hosted? If not, when will it be dropped? Third party API: I know the docs say...

      If it's too early in development for these questions, let me know.

      1. Is the source available yet? If so, where is it hosted? If not, when will it be dropped?
      2. Third party API: I know the docs say that the browser should be the client. However, after using tildes for awhile on mobile, it's quite... interesting. The site does really well on mobile, don't get me wrong, but it's missing the system feel that makes the experience pleasant. Honestly, one of the big reasons I was drawn to reddit was the ample support (by the third party) for mobile clients. I'd love to get started on a client for ~.
      14 votes