Skip to content

Instantly share code, notes, and snippets.

@harrisonmalone
Created April 9, 2020 06:07
Show Gist options
  • Save harrisonmalone/a37518e424ecb98c1a979d91710e8933 to your computer and use it in GitHub Desktop.
Save harrisonmalone/a37518e424ecb98c1a979d91710e8933 to your computer and use it in GitHub Desktop.
require "sinatra"
require "sinatra/json"
require "erb"
require "json"
# in memory database but could replace this with sqlite
tasks_database = [
{
"id": 1,
"name": "walk the dog",
"date": "20/04/2020"
},
{
"id": 2,
"name": "get washing off the line",
"date": "15/04/2020"
}
]
get "/task/:id" do
id = params["id"].to_i - 1
@task = tasks_database[id]
@hi = "hi"
erb :task
end
post "/task" do
task = JSON.parse(request.body.read)
p task
tasks_database << task
return "task added"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment