Last active
August 29, 2015 14:03
-
-
Save baronfel/8b1fbfae235e5084b17a to your computer and use it in GitHub Desktop.
Example of a RAML description for a REST API dealing with songs.
This file contains 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
#%RAML 0.8 | |
title: World Music API | |
baseUri: http://example.api.com/{version} | |
version: v1 | |
traits: | |
- paged: | |
queryParameters: | |
pages: | |
description: The number of pages to return | |
type: number | |
- secured: !include http://raml-example.com/secured.yml | |
/songs: | |
is: [ paged, secured ] | |
get: | |
queryParameters: | |
genre: | |
description: filter the songs by genre | |
post: | |
/{songId}: | |
get: | |
responses: | |
200:face | |
body: | |
application/json: | |
schema: | | |
{ "$schema": "http://json-schema.org/schema", | |
"type": "object", | |
"description": "A canonical song", | |
"properties": { | |
"title": { "type": "string" }, | |
"artist": { "type": "string" } | |
}, | |
"required": [ "title", "artist" ] | |
} | |
application/xml: | |
delete: | |
description: | | |
This method will *delete* an **individual song**" |
This file contains 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
module AST | |
type RamlDef = { | |
version : float | |
} |
This file contains 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
#%RAML 0.8 |
This file contains 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
open FParsec | |
open AST | |
open parser | |
match run parser.raml "#%RAML 0.8" with | |
| Success raml,_,_ -> printfn "success" | |
| Failure errorStr,ex,state -> printrn "failure :(" |
This file contains 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
open FParsec | |
let versionSentinel = skipString "#%RAML" |
This file contains 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
open FParsec | |
let versionSentinel = skipString "#%RAML" | |
let advanceToEOL = restOfLine true | |
let ramlVer = versionSentinel .>> ws >>. pfloat .>> advanceToEOL |
This file contains 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
open FParsec | |
open AST | |
let versionSentinel = skipString "#%RAML" | |
let advanceToEOL = restOfLine true | |
let ramlVer = versionSentinel .>> ws >>. pfloat .>> advanceToEOL | |
let makeRamlDef version = | |
{ | |
version = version | |
} | |
let raml = ramlVer |>> makeRamlDef |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment