-
-
Save robb1e/1362799 to your computer and use it in GitHub Desktop.
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" } | |
abstract class Param(){ | |
val name: String | |
val description: String | |
} | |
abstract class Endpoint { | |
val slug: String | |
val path: String | |
val stringFormat: String | |
lazy val requiredParams: List[Param] = List() | |
lazy val optionalParams: List[Param] = List() | |
val description: String | |
val method: HttpMethod | |
} |
object ApiResource extends Endpoint { | |
lazy val slug = "/resource" | |
... | |
} | |
implicit def endpoint2RouteMatcher(endpoint: Endpoint): RouteMatcher = new SinatraRouteMatcher(endpoint.path, requestPath) | |
get(ApiAction) { | |
... | |
} |
There's no reason why I'm not using org.scalatra.HttpMethod, we're only using this in one project for the moment, but if it proves useful I might pull it out into a common project. If I were to do that, can you point me to a good example of a library that produces HTML from an endpoint that I can copy the best practices from?
I did have a reason for not using case classes, but now I can't remember what that was. I could turn that into case classes quite easily.
I'm hoping to have it automatically register with scalatra based on the HttpMethod type, do you have a suggestion how that might work (based on your third point)?
If you or others think it might be useful, I'll happily pull this out into a common project if I can figure out some of the above.
Cheers
Robbie
Cool. A few comments:
org.scalatra.HttpMethod
, unless you're trying to keep this independent of Scalatra.