-
-
Notifications
You must be signed in to change notification settings - Fork 1
API
Manolo Cantón edited this page Sep 6, 2024
·
7 revisions
You can extend HTTPManagerAPI
to define methods which return requests. So you can use it in every scene by adding it with var _api := MyAPI.new()
where MyAPI
is the api.gd
class name. You can use _request
to create requests from route relative paths to routes
folder (without .tres
extension).
class_name MyAPI extends HTTPManagerAPI
func posts_index(q: String, page := 1, limit := 25) -> HTTPManagerRequest:
var params := { q = q }
if page > 1: params["page"] = page
if limit != 25: params["limit"] = clamp(limit, 1, 50)
# It must exist /routes/posts_index.tres
return _request("posts_index", params)
HTTPManagerAPIGroup
allows to split requests. You can create a subfolder in routes directory which contains:
-
HTTPManagerRoute
resources, -
api.gd
script that extendsHTTPManagerAPIGroup
.
After you add this line in your main api.gd
:
var posts := preload("routes/posts/api.gd").new()
Then editor autocompletes methods when you use _api.posts.
.