This backend can save stories that were created by the Story Creation Tool and provides endpoints to retrieve these stories.
The API is structured as the following:
GET
/story get list of all stories
/story/1 get metadata-json of story 1
/step/1/2/3/html get html of step 2.3 of story 1
/step/1/2/3/image get image of step 2.3 of story 1
POST
/add/story/ add new story
/add/step/1/2/3/ add step 2.3 to story 1
/add/step/1/2/3/html add html to step 2.3 of story 1
/add/step/1/2/3/image add image to step 2.3 of story 1
DELETE
/delete/story/1 delete story 1
/delete/step/1 delete all steps to story 1
/delete/step/1/2 delete all steps belonging to major step 2 of story 1
/delete/step/1/2/3 delete step 2.3 of story 1
Returns an overview over all stories
Returns the story.json file of a story with the respective id
Returns all step's data as json (not including images)
Returns html of a specific step of a specific story
Returns image of a specific step of a specific story
Creates a new story entry. (metadata only)
expects in body
- name (string): the name of the story
- category (string): the story category
- story_json (string): the story structure as json (originally the "story json file")
example curl:
`curl -XPOST -d '{"name": "My New Story", "category" : "test", "story_json" : "{\"relevant json\" : \"as a string\"}"}' -H 'content-type: application/json' localhost:3000/add/story`
Creates a story "step" for the story specified in `:storyID` (as created by /add/story). The `:step_major` and `:step_major` parameters are the equivalent of the `1-2.html` notation we originally have in the file names.
expects in body
- html content of the step (as character string)
example curl:
`curl -XPOST -d '{"html": "<blink>does this html tag still work?</blink>"}' -H 'content-type: application/json' localhost:3000/add/step/1/2/3`
post a steps html content. The matching story and step must have been created first!
example curl:
curl -X POST localhost:3000/add/step/1/1/1/html -H 'Content-Type: application/json' -d '{"html":"some <b>story</b> content!"}'
post an image. The matching story and step must have been created first!
example curl:
curl -F "image=@./testimage.png" localhost:3000/add/step/1/1/1/image
delete a story and all its steps. Note: Stories can only be deleted if ALL steps belonging to that story have been deleted first (see /delete/step/)!
example curl:
curl -X "DELETE" localhost:3000/delete/story/1
delete all steps belonging to a story
example curl (delete all steps of story 1):
curl -X "DELETE" localhost:3000/delete/step/1
delete all steps with the same major step belonging to a story
example curl (delete step 2.x of story 1):
curl -X "DELETE" localhost:3000/delete/step/1/1
delete a minor step in a story
example curl (delete step 2.3 of story 1):
curl -X "DELETE" localhost:3000/delete/step/1/2/3
(following this tutorial)
- install postgresql with homebrew (on Linux / OsX):
brew install postgresql
brew services start postgresql
(you can stop services withbrew services stop postgresql
)
- create a new user and database in psql console
psql postgres
CREATE ROLE me WITH LOGIN PASSWORD 'password';
CREATE DATABASE stories;
\q
- then run database init file in /db/setup/
psql -U me -d stories -a -f ./db/setup/db_setup.sql