How to Search via HTTP API

Hi all! :waving_hand:

I’m new to SilverBullet, but extremely impressed by how flexible and powerful it is. I’m a Web Developer that uses Webstudio, a frontend tool that can be used to build static websites that can use data from external third-party databases and CMSs. My intention is to try and use SilverBullet as my primary ‘backend’, using it as a ‘blog engine’, as well as a possible backend for ecommerce stores, photographic galleries and portfolios, and more.

In order to do that, I need to be able to access SilverBullet via its HTTP API — which is very easy. The only problem is that for the majority of operations I will need to perform some kind of search in order to get either one or at most a few pages. Think, for example, of being able to search for all blog posts that were written by a certain author, or that have a certain hashtag, or even just listing the ‘6 latest posts’.

The HTTP API page in the SilverBullet manual doesn’t seem to mention anything about how to perform searches and retrieve specific pages/objects via the API… Am I missing something obvious? Any guidance would be greatly appreciated!

The server component of SilverBullet is pretty barebones. It’s mostly just to sync data, not really performing any other operations.

Now there is a /.shell/ endpoint where you can send a shell command and get the output. So you could just create any kind of ‘endpoint’ you want with that.

For example, create a script that can search with (rip)grep and then format the output as JSON (or whatever format your client can handle).

:warning: This shell endpoint is also one of the reason’s why it’s so important to secure SilverBullet and to not run it as root.

1 Like

Webstudio can take markdown directly, and apply the formatting we’re using on the frontend automatically, which is perfect. This is one of the reasons we are keen on SilverBullet!

Another reason, however, is Objects — the ability to query object metadata/frontmatter. If we have to write shell scripts that produce output the way we want, we’ll basically need to rewrite much of the querying functionality already built-into SilverBullet, which we have available with space-lua queries and expressions…

Question: when we add space-lua code to a page, and we then retrieve the page via API, do we get the original code block, or the evaluated result? Is there a way to specify that we want the result? If we can do that, then maybe we can build special pages that can do the querying for us… :crossed_fingers::folded_hands:

I’ve added a feature request on Github, as it doesn’t seem like this is possible — which is a deal-breaker for us, as it means SilverBullet simply cannot be used as a backend, unless we’re willing to custom code all the searching/querying functionality as shell commands… :sob: