Created
April 9, 2020 06:07
-
-
Save harrisonmalone/a37518e424ecb98c1a979d91710e8933 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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