-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sdk): unable to use path variables in cloud.Api (#3931)
Fixes #3919 ## Checklist - [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted) - [ ] Description explains motivation and solution - [x] Tests added (always) - [ ] Docs updated (only required for features) - [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing *By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
- Loading branch information
Showing
13 changed files
with
2,336 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
bring cloud; | ||
bring http; | ||
|
||
let api = new cloud.Api(); | ||
|
||
|
||
let handler = inflight (req: cloud.ApiRequest): cloud.ApiResponse => { | ||
return cloud.ApiResponse { | ||
body: Json.stringify({ user: req.vars.get("name") }), | ||
headers: { "content-type" => "application/json" }, | ||
status: 200 | ||
}; | ||
}; | ||
|
||
let handler_two = inflight (req: cloud.ApiRequest): cloud.ApiResponse => { | ||
return cloud.ApiResponse { | ||
body: Json.stringify({ user: req.vars.get("name"), age: req.vars.get("age") }), | ||
headers: { "content-type" => "application/json" }, | ||
status: 200 | ||
}; | ||
}; | ||
|
||
api.get("/users/{name}", handler); | ||
api.get("/{name}", handler); | ||
api.get("/users/permission/{name}", handler); | ||
api.get("/{name}/{age}", handler_two); | ||
|
||
test "test" { | ||
let username = "tsuf"; | ||
let res: http.Response = http.get("${api.url}/users/${username}"); | ||
|
||
|
||
assert(res.status == 200); | ||
assert(Json.parse(res.body ?? "").get("user") == username); | ||
} | ||
|
||
test "test2" { | ||
let username = "akhil"; | ||
let res: http.Response = http.get("${api.url}/${username}"); | ||
|
||
|
||
assert(res.status == 200); | ||
assert(Json.parse(res.body ?? "").get("user") == username); | ||
} | ||
|
||
test "test3" { | ||
let username = "akhil"; | ||
let res: http.Response = http.get("${api.url}/users/permission/${username}"); | ||
|
||
|
||
assert(res.status == 200); | ||
assert(Json.parse(res.body ?? "").get("user") == username); | ||
} | ||
|
||
test "test4" { | ||
let username = "akhil"; | ||
let age = "23"; | ||
let res: http.Response = http.get("${api.url}/${username}/${age}"); | ||
|
||
|
||
assert(res.status == 200); | ||
assert(Json.parse(res.body ?? "").get("user") == username); | ||
assert(Json.parse(res.body ?? "").get("age") == age); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.