Created
November 13, 2011 22:01
-
-
Save robb1e/1362799 to your computer and use it in GitHub Desktop.
Creating API docs for scalatra
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object ApiResource extends Endpoint { | |
lazy val slug = "/resource" | |
... | |
} | |
implicit def endpoint2RouteMatcher(endpoint: Endpoint): RouteMatcher = new SinatraRouteMatcher(endpoint.path, requestPath) | |
get(ApiAction) { | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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