Fortune.js is handy for prototyping JSON:API formatted APIs.
This example extends Fortune's Getting Started guide to demonstrate a simple prototype using the JSON:API serializer and seedable memory adapter.
It's a handy combination for testing and prototyping: the .jsonl seed files (found in the db
directory of this repo) are easy to read and edit manually, and with just a few lines of code Fortune can serialize their contents as a JSON:API.
git clone https://github.com/redoPop/fortunejs-example.git
cd fortunejs-example
npm install
npm start
The JSON:API is now available on port 1337 of your localhost.
To keep things simple, I've stuck with the original example presented in the Fortune.js Getting Started guide: a basic API for a Twitter-like service consisting of only /users
and /posts
. You'll find the schema definition in lib/store.js
, along with some expository comments.
I've intentionally avoided transformations and other techniques introduced in Fortune's guide to focus this example on JSON:API serialization of data.
To the same end, I've also added some seed data which you'll find in the db
directory of this repository (db/post.jsonl
, db/user.jsonl
).
curl -X "GET" "http://localhost:1337/posts"
curl -X "POST" "http://localhost:1337/posts" \
-H "Content-Type: application/vnd.api+json" \
-d $'{
"data": {
"type": "posts",
"attributes": {
"message": "My name is Catbug!"
},
"relationships": {
"author": {
"data": {"id": 5, "type": "users"}
}
}
}
}'