examples: fullstack vweb example (#16761)

This commit is contained in:
Hitalo Souza 2023-01-05 22:36:42 -03:00 committed by GitHub
parent 43d8bc30f9
commit 0146509516
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 759 additions and 0 deletions

View file

@ -0,0 +1,36 @@
module main
import json
import net.http
pub fn get_users(token string) ![]User {
mut header := http.new_header()
header.add_custom('token', token)!
url := 'http://localhost:8082/controller/users'
mut config := http.FetchConfig{
header: header
}
resp := http.fetch(http.FetchConfig{ ...config, url: url })!
users := json.decode([]User, resp.body)!
return users
}
pub fn get_user(token string) !User {
mut header := http.new_header()
header.add_custom('token', token)!
url := 'http://localhost:8082/controller/user'
mut config := http.FetchConfig{
header: header
}
resp := http.fetch(http.FetchConfig{ ...config, url: url })!
users := json.decode(User, resp.body)!
return users
}