-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebapi.jl
45 lines (33 loc) · 1.01 KB
/
webapi.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
include("pacman.jl")
using Genie, Genie.Renderer.Json, Genie.Requests, HTTP
using UUIDs
instances = Dict()
route("/simulations", method=POST) do
payload = jsonpayload()
model = initialize_model()
id = string(uuid1())
instances[id] = model
agents = []
for robots in allagents(model)
push!(agents, robots)
end
sort!(agents, by=x -> x.id)
json(Dict("Location" => "/simulations/$id", "agents" => agents))
end
route("/simulations/:id") do
println(payload(:id))
model = instances[payload(:id)]
run!(model, 1)
agents = []
for robots in allagents(model)
push!(agents, robots)
end
sort!(agents, by=x -> x.id)
json(Dict("agents" => agents))
end
Genie.config.run_as_server = true
Genie.config.cors_headers["Access-Control-Allow-Origin"] = "*"
Genie.config.cors_headers["Access-Control-Allow-Headers"] = "Content-Type"
Genie.config.cors_headers["Access-Control-Allow-Methods"] = "GET,POST,PUT,DELETE,OPTIONS"
Genie.config.cors_allowed_origins = ["*"]
up()