WriteFreely API
Today, while messing around with WriteFreely configuration and logs, I have become aware of the API endpoints. I did know about the API before, but I never set to actually look at what is possible to do.
The most useful open endpoint is probably /api/collections
. Every user on a WriteFreely instance has a collection (of posts) associated with its username; in my case, this is /api/collections/nick
. Under this path, the /api/collections/nick/posts
endpoint retrieves some meta information and the 10 latest posts (if the blog uses the “Blog” display format):
$ curl -s https://blog.nvitucci.social/api/collections/nick/posts
A tool like jq
can be useful for a quick inspection from the command line. For example, you can retrieve the title of the blog and the total number of posts with the following command:
$ curl -s https://blog.nvitucci.social/api/collections/nick/posts | jq '.data.title, .data.total_posts'
You can also see the title of the 10 latest posts:
$ curl -s https://blog.nvitucci.social/api/collections/nick/posts | jq '.data.posts[].title'
Since the page size is set to 10 (and apparently it cannot be changed), you can calculate the number of pages and then paginate the result using the page
parameter:
$ curl -s https://blog.nvitucci.social/api/collections/nick/posts?page=2 | jq '.data.posts[].title'
The complete documentation of the WriteFreely API is available here.