| 1 | module main |
| 2 | |
| 3 | import json |
| 4 | import net.http |
| 5 | |
| 6 | pub fn get_products(token string) ![]Product { |
| 7 | mut header := http.new_header() |
| 8 | header.add_custom('token', token)! |
| 9 | url := 'http://localhost:8082/controller/products' |
| 10 | |
| 11 | mut config := http.FetchConfig{ |
| 12 | header: header |
| 13 | } |
| 14 | |
| 15 | resp := http.fetch(http.FetchConfig{ ...config, url: url })! |
| 16 | products := json.decode([]Product, resp.body)! |
| 17 | |
| 18 | return products |
| 19 | } |
| 20 | |
| 21 | pub fn get_user(token string) !User { |
| 22 | mut header := http.new_header() |
| 23 | header.add_custom('token', token)! |
| 24 | |
| 25 | url := 'http://localhost:8082/controller/user' |
| 26 | |
| 27 | mut config := http.FetchConfig{ |
| 28 | header: header |
| 29 | } |
| 30 | |
| 31 | resp := http.fetch(http.FetchConfig{ ...config, url: url })! |
| 32 | user := json.decode(User, resp.body)! |
| 33 | |
| 34 | return user |
| 35 | } |
| 36 | |