+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
+
+ # Write data as JSON and set the right content type header.
+ fun raw_json(json: nullable String, status: nullable Int) do
+ header["Content-Type"] = media_types["json"].as(not null)
+ if json == null then
+ send(null, status)
+ else
+ send(json, status)
+ end
+ end
+end
+
+# An error returned by the API.
+#
+# Can be serialized to json.
+class APIError
+ serialize
+
+ # Reponse status
+ var status: Int
+
+ # Response error message
+ var message: String
+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 Serializable
+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 core_serialize_to(v) do
+ v.serialize_attribute("web_url", mentity.web_url)
+ v.serialize_attribute("api_url", mentity.api_url)
+ v.serialize_attribute("name", mentity.name)
+ end
+end
+
+# A namespace token representation
+#
+# Used for namespace tokens like `::`, `>` and `$`
+redef class String
+ super NSEntity
+end
+