nitc :: APIHandler
nitc :: APIHandler :: defaultinit
nitc :: APIHandler :: find_mentity
Find the MEntitywith
full_name`.
nitc :: APIHandler :: mentity_from_uri
Try to load the mentity from uri with/:id
.
nitc :: APIHandler :: paginate
Paginate a json arraynitc $ APIHandler :: SELF
Type of this instance, automatically specialized in every classpopcorn :: Handler :: _body_type
popcorn :: Handler :: _validator
Validator used to check body inputpopcorn :: Handler :: body_type=
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
popcorn :: Handler :: defaultinit
nitc :: APIHandler :: defaultinit
core :: Object :: defaultinit
popcorn :: Handler :: deserialize_body
Deserialize the request bodynitc :: APIHandler :: find_mentity
Find the MEntitywith
full_name`.
all(req, res)
if route
matches uri
.
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
nitc :: APIHandler :: mentity_from_uri
Try to load the mentity from uri with/:id
.
core :: Object :: native_class_name
The class name of the object in CString format.core :: Object :: output_class_name
Display class name on stdout (debug only).nitc :: APIHandler :: paginate
Paginate a json arraypopcorn :: Handler :: validate_body
Validate body input withvalidator
popcorn :: Handler :: validator
Validator used to check body inputpopcorn :: Handler :: validator=
Validator used to check body inputnitc :: APIDocdown
Docdown handler accept docdown as POST data and render it as HTMLnitc :: APICatalogContributing
Get the list of mpackages contributed by a personnitc :: APIEntityLinearization
Linearize super definitions of a MClassDef or a MPropDef if any.nitc :: APIIniContribFileContent
Get the package contrib file contentnitc :: APIIniLicenseFileContent
Get the package license file content
# Specific handler for the nitweb API.
abstract class APIHandler
super Handler
# App config.
var config: NitwebConfig
# Find the MEntity ` with `full_name`.
fun find_mentity(full_name: nullable String): nullable MEntity do
if full_name == null then return null
var mentity = config.model.mentity_by_full_name(full_name.from_percent_encoding, config.filter)
if mentity == null then return null
var filter = config.filter
if filter == null or filter.accept_mentity(mentity) then return mentity
return null
end
# Try to load the mentity from uri with `/:id`.
#
# Send 400 if `:id` is null.
# Send 404 if no entity is found.
# Return null in both cases.
fun mentity_from_uri(req: HttpRequest, res: HttpResponse): nullable MEntity do
var id = req.param("id")
if id == null then
res.api_error(400, "Expected mentity full name")
return null
end
var mentity = find_mentity(id)
if mentity == null then
res.api_error(404, "MEntity `{id}` not found")
end
return mentity
end
# Paginate a json array
#
# Returns only a subset of `results` depending on the current `page` and the
# number of elements to return set by `limit`.
#
# Transforms the json array into an object:
# ~~~json
# {
# "page": 2,
# "limit": 10,
# "results: [ ... ],
# "max": 5,
# "total": 49
# }
# ~~~
fun paginate(results: JsonArray, count: Int, page, limit: nullable Int): JsonObject do
if page == null or page <= 0 then page = 1
if limit == null or limit <= 0 then limit = 20
var max = count / limit
if max == 0 then
page = 1
max = 1
else if page > max then
page = max
end
var lstart = (page - 1) * limit
var lend = limit
if lstart + lend > count then lend = count - lstart
var res = new JsonObject
res["page"] = page
res["limit"] = limit
res["results"] = new JsonArray.from(results.subarray(lstart, lend))
res["max"] = max
res["total"] = count
return res
end
end
src/doc/api/api_base.nit:50,1--125,3