RAML 1.0: Design, Build, Test, Document, & Share Your API
-
Upload
michael-stowe -
Category
Technology
-
view
325 -
download
4
Transcript of RAML 1.0: Design, Build, Test, Document, & Share Your API
l All contents Copyright © 2014, MuleSoft Inc.
RAML 1.0Design, Build, Test, Document, Share
by mike stowe
l All contents Copyright © 2014, MuleSoft Inc.
• API Fanatic
• Open Source Contributor
• Author, Speaker, Consultant
• 10+ years hacking Professional Code
• Dev Relations Manager at MuleSoft
About Me
@mikegstowe
l All contents Copyright © 2014, MuleSoft Inc.4
...people are fairly good at short-term design, and usually awful at long-term design.”
“
-Dr. Roy Fielding
l All contents Copyright © 2014, MuleSoft Inc.14
How we build APIs
Drop Stories Lwill be next “version”
l All contents Copyright © 2014, MuleSoft Inc.15
How we build APIs
Skip planning needs, we can focus on this later
l All contents Copyright © 2014, MuleSoft Inc.20
How we build APIs
Find Bugs, Inconsistencies, Issues
l All contents Copyright © 2014, MuleSoft Inc.23
How we build APIs
How do we do this without breaking everything???
l All contents Copyright © 2014, MuleSoft Inc.
When you think about it… the API Design Process isn’t just inefficient...
l All contents Copyright © 2014, MuleSoft Inc.27
We have to learn to rethink differently.”“- Andrew Curioso, Cloud Architect
l All contents Copyright © 2014, MuleSoft Inc.
What if you could controlthe entire API Lifecycle, reduce design flaws, and eliminate redundancies?
l All contents Copyright © 2014, MuleSoft Inc.
Empowering architects, developers, tech writers, and support to work more efficiently by doing what they’re best at.
l All contents Copyright © 2014, MuleSoft Inc.32
• RAML is an open source specification for DESCRIBING APIs
• RAML is surrounded by an open source community with over
100 projects in 12 programming languages
What is RAML?
l All contents Copyright © 2014, MuleSoft Inc.33
• RAML is backed by a working group consisting members from
MuleSoft, Akana, Cisco, Intuit, Airware, VMware,
ProgrammableWeb, and Angular.js
• RAML is used commercially by thousands of companies
including Spotify, Cisco, VMware, PBS, Sonic, and more
Who is RAML?
l All contents Copyright © 2014, MuleSoft Inc.34
• Akana, AWS, CA Technologies, MuleSoft,
Restlet, Software AG, Gelato, APImatic, REST
United, API Fortress, API Metrics, API Science,
Parasoft, PAW, Postman, SandBox, SmartBear,
Oracle, SAP…
Who supports RAML?
l All contents Copyright © 2014, MuleSoft Inc.35
• You can define your API in just a few lines of code
• You can see what it would look like as you go
• You can quickly prototype it for devs to try
• You can quickly make tweaks/ changes
• You can easily document your API
• You can let developers try your API online
• You can let developers interact with your and other APIs
• Generate SDKs/ client libraries for your API
What can you do with RAML?
l All contents Copyright © 2014, MuleSoft Inc.36
• You can use and force design patterns
• You can reuse code (libraries, traits, resourceTypes, overlays)
More Importantly…
resourceTypes:- collection:
description: Collection of available <<resourcePathName>> in Jukebox.get:description: Get a list of <<resourcePathName>>.responses:
200:body:
application/json:example: |
<<exampleCollection>>
l All contents Copyright © 2014, MuleSoft Inc.38
What Does RAML Look Like?
#%RAML 1.0title: World Music APIbaseUri: http://example.api.com/{version}version: v1/playlists:
get:responses:
200:body:
application/json:example: |{ “playlistID” : 1, “playlistName” : “My Awesome Playlist”, “genre” : “top40”,“songs” : 40
}
l All contents Copyright © 2014, MuleSoft Inc.42
Writing RAML: Getting Started
#%RAML 1.0title: World Music APIbaseUri: http://example.api.com/{version}version: v1
l All contents Copyright © 2014, MuleSoft Inc.44
Writing RAML: Creating Resources
#%RAML 1.0title: World Music APIbaseUri: http://example.api.com/{version}version: v1/playlists:
description: This is my descriptionget:description: get a collection of playlists
/{id}:description: access a specific playlist by IDget:
description: get a playlist by ID
l All contents Copyright © 2014, MuleSoft Inc.46
Creating RAML: Schemas & Examples
…/playlists:
get:responses:
200:body:
application/json:example: |
{ “playlistID” : 1, “playlistName” : “My Awesome Playlist”, “genre” : “top40”,“songs” : 40
}
l All contents Copyright © 2014, MuleSoft Inc.47
Creating RAML: Schemas & Examples
…/playlists:
get:responses:
200:body:
application/json:example: !include examples/example.jsonschema: !include schemas/example.json
application/xml:example: !include examples/example.xmlschema: !include schemas/example.xml
l All contents Copyright © 2014, MuleSoft Inc.49
Creating RAML: ResourceTypes
#%RAML 1.0title: World Music API
resourceTypes:collection:get:responses:200:body:application/json:
example: <<exampleResp>>schema: <<schemaResp>>
500:body:application/json:example: <<errorResp>>
l All contents Copyright © 2014, MuleSoft Inc.50
Creating RAML: ResourceTypes
#%RAML 1.0title: World Music API…
/playlists:type:collection:exampleResp: {"example" : "provided"}schemaResp: {"schema" : "provided"}errorResp: {"error" : "provided"}
l All contents Copyright © 2014, MuleSoft Inc.52
Creating RAML: Data Types
#%RAML 1.0title: World Music API…
types:playlist:type: objectproperties:name:
type: stringsongs:
type: object[]
l All contents Copyright © 2014, MuleSoft Inc.53
Creating RAML: Data Types
…/playlists:get:responses:200:body:application/json:type: playlist
l All contents Copyright © 2014, MuleSoft Inc.55
Creating RAML: Libraries
#%RAML 1.0 Library
resourceTypes:collection:
types:playlist:type: object
properties:name:
type: stringsongs:
type: object[]
l All contents Copyright © 2014, MuleSoft Inc.56
Creating RAML: Libraries
#%RAML 1.0…uses:
playlist: libraries/playlist.raml
/playlists:type:playlist.collection:
get:responses:200:body:application/json:
type: playlist.playlist
l All contents Copyright © 2014, MuleSoft Inc.58
Creating RAML: Overlays
#%RAML 1.0 Overlay
/playlists:description: Add in a description over the
original Spec
l All contents Copyright © 2014, MuleSoft Inc.59
Creating RAML: Overlays
#%RAML 1.0 Extension
baseUri: http://adminApi.domain.com
/playlists:delete:
description: only admins get access to this
l All contents Copyright © 2014, MuleSoft Inc.72
Learn More about RAML 1.0
RAML website:http://raml.org
Twitter: @ramlapi
Pick up our Pocket Guide to RAML 1.0before you leave J
l All contents Copyright © 2014, MuleSoft Inc.
• Define your API before Coding
• Use Design Patterns/ Code Reuse
• Mock and get User Feedback
• Make Necessary Changes
• Start Coding – to the Spec
• DO NOT DEVIATE!
Use Spec Driven Development
l All contents Copyright © 2014, MuleSoft Inc.75
Hybrid Approach
Design Development
Continuous, fluid, changeable Static… No turns
l All contents Copyright © 2014, MuleSoft Inc.77
Learn More about RAML 1.0
RAML website:http://raml.org
Twitter: @ramlapi
Pick up our Pocket Guide to RAML 1.0before you leave J