| 1 | module main |
| 2 | |
| 3 | fn home_controller() ![]u8 { |
| 4 | response := 'HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 13\r\n\r\nHello, World!' |
| 5 | return response.bytes() |
| 6 | } |
| 7 | |
| 8 | fn get_user_controller(id string) ![]u8 { |
| 9 | body := 'User ID: ${id}' |
| 10 | content_length := body.len |
| 11 | response := 'HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: ${content_length}\r\n\r\n${body}' |
| 12 | return response.bytes() |
| 13 | } |
| 14 | |
| 15 | fn create_user_controller() ![]u8 { |
| 16 | body := 'User created successfully' |
| 17 | content_length := body.len |
| 18 | response := 'HTTP/1.1 201 Created\r\nContent-Type: text/plain\r\nContent-Length: ${content_length}\r\n\r\n${body}' |
| 19 | return response.bytes() |
| 20 | } |
| 21 | |
| 22 | fn not_found_response() ![]u8 { |
| 23 | body := '404 Not Found' |
| 24 | content_length := body.len |
| 25 | response := 'HTTP/1.1 404 Not Found\r\nContent-Type: text/plain\r\nContent-Length: ${content_length}\r\n\r\n${body}' |
| 26 | return response.bytes() |
| 27 | } |
| 28 | |