I took little break from Cantilever for a few days - indeed, a break from everything - with a short holiday in the Canaries. It was great to feel some winter sun, to escape the gloom of Scotland in December, and to see my parents. It was my first trip abroad since Covid. I'm not a great traveller at the best of times, and I still felt needlessly nervous about the trip. But I am glad I went.
Bit of a bumpy landing, literately and figuratively, going from 20C in Fuerteventura to -2C in Edinburgh.
Now that I am back, I've continued to refine my router serialization mechanisms. Specifically, my API needs to be able to return JSON files wrapped in an API Result class. This has taken quite a bit of work, and requires me to use a just-released version of kotlinx.serialization (1.5.0-RC, so not even a final version of that library). It works - almost. Perhaps it works well enough. Compare what I have:
{
"statusCode":200,
"headers":
{"Content-Type":"application/json"},
"body":"{\"jsonString\":{ \"layouts\": { \"templates\": { \"templates/post.html.hbs\": { \"key\": \"templates/post.html.hbs\", \"lastUpdated\": \"2023-01-12T22:50:59\" }, \"templates/news.html.hbs\": { \"key\": \"templates/news.html.hbs\", \"lastUpdated\": \"2023-01-14T08:27:17\" } } }, \"items\": { \"posts\": { \"sources/20230107.md\": { \"title\": \"Adding Templating\", \"srcKey\": \"sources/20230107.md\", \"url\": \"adding-templating\", \"template\": { \"key\": \"templates/post.html.hbs\", \"lastUpdated\": \"2023-01-12T22:50:59\" }, \"lastUpdated\": \"2023-01-14T10:34:09.936271\" } } }}}"
}
With what I want:
{
"statusCode":200,
"headers":
{"Content-Type":"application/json"},
"body":"{ \"layouts\": { \"templates\": { \"templates/post.html.hbs\": { \"key\": \"templates/post.html.hbs\", \"lastUpdated\": \"2023-01-12T22:50:59\" }, \"templates/news.html.hbs\": { \"key\": \"templates/news.html.hbs\", \"lastUpdated\": \"2023-01-14T08:27:17\" } } }, \"items\": { \"posts\": { \"sources/20230107.md\": { \"title\": \"Adding Templating\", \"srcKey\": \"sources/20230107.md\", \"url\": \"adding-templating\", \"template\": { \"key\": \"templates/post.html.hbs\", \"lastUpdated\": \"2023-01-12T22:50:59\" }, \"lastUpdated\": \"2023-01-14T10:34:09.936271\" } } }}"
}
The difference is slight, but there's one extra json key in the body that I don't need - jsonString
- that is an artifact of the internal representation of the API result classes. I've asked for help to see if it can be avoided (I have reasons to believe it can be) but it is not a deal-breaker. If that extra key needs to remain, then my front-end apps will need to work a little harder to process the content, but it should be achievable.
All that work...
... and possibly for nothing. Perhaps I don't need to return the structure.json
file directly. I can deserialize it and re-serialize it - which is what I did initially but I was getting some pretty mangled, invalid Json. All my code changes and improvements have fixed that now. Here's the output:
{"statusCode":200,"headers":{"Content-Type":"application/json"},"body":"{\"myCustomData\":{\"layouts\":{\"templates\":{\"templates/post.html.hbs\":{\"key\":\"templates/post.html.hbs\",\"lastUpdated\":\"2023-01-12T22:50:59\"},\"templates/news.html.hbs\":{\"key\":\"templates/news.html.hbs\",\"lastUpdated\":\"2023-01-14T08:27:17\"}}},\"items\":{\"posts\":{\"sources/20230107.md\":{\"title\":\"Adding Templating\",\"srcKey\":\"sources/20230107.md\",\"url\":\"adding-templating\",\"template\":{\"key\":\"templates/post.html.hbs\",\"lastUpdated\":\"2023-01-12T22:50:59\"},\"lastUpdated\":\"2023-01-14T10:34:09.936271\"}}}}}"}
Again, we have one extra key - myCustomData
- that I don't need or want. But could probably live with.
There's nothing for it. I can't put it off any longer.
I need to start writing a front-end.
Prev: Serializing Failures Next: Exploring authentication of routes