aboutsummaryrefslogtreecommitdiff
path: root/examples/webserver.sloth
blob: abbead3db9324b484e635cbc959cf086c2a4d011 (plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# Include the external dependency itself as a module named "slow_api"
use extern "slowapi" as slow_api;

# Use some things from the "slow_api" module
use std::serde::Serializable;
use std::serde::format::Json;

use slow_api::{SlowAPI, Method};

# Construct a slow API server
val server = SlowApi();

type Person derives Serializable = {
    name: String,
    age: Option<String>
};

fn hello_route(
    name: Argument<String>, 
    age: Argument<Option<String>>,
) -> Json<Person> {
    Person { name, age }
}

# Start the server
server
    .route(Method::GET, "/hello", hello_route)
    .start("0.0.0.0:8000");
#










































###
type Poggies;

trait Constructor<..T> {
    fn new(..T) -> Self;
}

impl Constructor<> for Poggies {
    fn new() -> Self {
        #
    }
}

impl<T: Constructor<>> Default for T {
    fn default() -> Self {
        Self::new()
    }
}

###
type Person = {
    name: String,
    age: i32,
};

type Person derives Serialize, Deserialize = {
    name: String,
    age: i32,
};

@route::get("/teacup") #      vvvvvv - Requires T to implement Serialize
fn teacup_route() -> Response<Person> {
    Response(418, Person {
        name: "Cody Q",
        age: 17,
    })
}