+# A Rooter dedicated to APIHandlers.
+class APIRouter
+ super Router
+
+ # App config
+ var config: NitwebConfig
+end
+
+redef class HttpResponse
+
+ # Return an HTTP error response with `status`
+ #
+ # Like the rest of the API, errors are formated as JSON:
+ # ~~~json
+ # { "status": 404, "message": "Not found" }
+ # ~~~
+ fun api_error(status: Int, message: String) do
+ json(new APIError(status, message), status)
+ end
+end
+
+# An error returned by the API.
+#
+# Can be serialized to json.
+class APIError
+ super Jsonable
+
+ # Reponse status
+ var status: Int
+
+ # Response error message
+ var message: String
+
+ # Json Object for this error
+ var json: JsonObject is lazy do
+ var obj = new JsonObject
+ obj["status"] = status
+ obj["message"] = message
+ return obj
+ end
+
+ redef fun serialize_to(v) do json.serialize_to(v)
+end
+
+# Fullname representation that can be used to build decorated links
+#
+# * MPackage: `mpackage_name`
+# * MGroup: `(mpackage_name::)mgroup_name`
+class Namespace
+ super Array[nullable NSEntity]
+ super NSEntity
+ serialize
+
+ redef fun to_s do return self.join("")
+ redef fun serialize_to(v) do to_a.serialize_to(v)
+end
+
+# Something that goes in a Namespace
+#
+# Can be either:
+# * a `NSToken` for tokens like `::`, `>` and `$`
+# * a `MSRef` for references to mentities
+interface NSEntity
+ super Jsonable
+end
+
+# A reference to a MEntity that can be rendered as a link.
+#
+# We do not reuse `MEntityRef` ref since NSRef can be found in a ref and create
+# an infinite loop.
+class NSRef
+ super NSEntity
+ serialize
+
+ # The mentity to link to/
+ var mentity: MEntity
+
+ redef fun serialize_to(v) do
+ var obj = new JsonObject
+ obj["web_url"] = mentity.web_url
+ obj["api_url"] = mentity.api_url
+ obj["name"] = mentity.name
+ obj.serialize_to(v)
+ end
+end
+
+# A namespace token representation
+#
+# Used for namespace tokens like `::`, `>` and `$`
+redef class String
+ super NSEntity
+end
+