mirror of
https://github.com/vlang/v.git
synced 2025-09-15 23:42:28 +03:00
examples: fullstack vweb example (#16761)
This commit is contained in:
parent
43d8bc30f9
commit
0146509516
27 changed files with 759 additions and 0 deletions
36
examples/vweb_fullstack/src/user_view_api.v
Normal file
36
examples/vweb_fullstack/src/user_view_api.v
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue