casualjim
11/30/2011 - 11:19 PM

Creating API docs for scalatra

Creating API docs for scalatra

object ApiResource extends Endpoint {
  val slug = "/resource"
 ...
}

implicit def endpoint2RouteMatcher(endpoint: Endpoint): RouteMatcher = new SinatraRouteMatcher(endpoint.path, requestPath)

get(ApiAction) {
  ...
}
class HttpMethod

object HttpPostMethod extends HttpMethod { override def toString = "POST" }
object HttpGetMethod extends HttpMethod { override def toString = "GET" }
object HttpDeleteMethod extends HttpMethod { override def toString = "DELETE" }
object HttpPutMethod extends HttpMethod { override def toString = "PUT" }

trait Param {
  def name: String
  def description: String
}

trait Endpoint {
  def slug: String
  def path: String
  def stringFormat: String
  lazy val requiredParams: List[Param] = List()
  lazy val optionalParams: List[Param] = List()
  def description: String
  def method: HttpMethod
}