glts
glts

Reputation: 22734

Exposing Datomic entity identities to a service or REST API

I’m confused about how to expose the identity of a Datomic entity to a service or API.

Suppose I have a REST API endpoint

/api/post/<id>

where <id> identifies some blog post (a blog post entity).

With a relational database backend I might have <id> be of some serial integer type stored in a column named id in a table named post.

Since Datomic doesn’t have tables (entities) in the same sense, and its entity IDs are unique database-wide I wonder how this is usually done with Datomic?

Upvotes: 4

Views: 466

Answers (1)

Valentin Waeselynck
Valentin Waeselynck

Reputation: 6051

Unless the endpoint is ephemeral, you should really not expose the entity number (see here for detailed reasons), so using the value of an identity attribute is a good way to go about this. This attribute can be of type UUID indeed, but Strings or numbers can work too.

With Datomic, you also have the opportunity to use "self-contained" identifiers, e.g Datomic lookup refs ([:post/id "fdslkjfdskjfsl"] instead of just "fdslkjfdskjfsl"). This comes in handy to make your route less specific than being about posts. Because of Datomic's schema flexibility (compared to say SQL tables or MongoDB collections), this benefit is especially easy to achieve. You could implement this e.g by edn-encoding the lookup ref in the URL.

Upvotes: 4

Related Questions