RAML 1.0: Design, Build, Test, Document, & Share Your API

79
l All contents Copyright © 2014, MuleSoft Inc. RAML 1.0 Design, Build, Test, Document, Share by mike stowe

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.

Let’s build an API

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.5

How we build APIs

We need an API…

l All contents Copyright © 2014, MuleSoft Inc.6

How we build APIs

WE need an API…

l All contents Copyright © 2014, MuleSoft Inc.7

How we build APIs

API Style/ Design

l All contents Copyright © 2014, MuleSoft Inc.8

How we build APIs

User Stories

l All contents Copyright © 2014, MuleSoft Inc.9

How we build APIs

Start Coding

l All contents Copyright © 2014, MuleSoft Inc.10

How we build APIs

Timeline Issues

l All contents Copyright © 2014, MuleSoft Inc.11

How we build APIs

Add More Resources

l All contents Copyright © 2014, MuleSoft Inc.12

How we build APIs

Let’s Collaborate*

l All contents Copyright © 2014, MuleSoft Inc.13

How we build APIs

Write lots of code… FAST

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.16

How we build APIs

Testing/ Stage!!!

l All contents Copyright © 2014, MuleSoft Inc.17

How we build APIs

Production!!!

l All contents Copyright © 2014, MuleSoft Inc.18

How we build APIs

Document API

l All contents Copyright © 2014, MuleSoft Inc.19

How we build APIs

Create SDKs, Mobile Apps, etc

l All contents Copyright © 2014, MuleSoft Inc.20

How we build APIs

Find Bugs, Inconsistencies, Issues

l All contents Copyright © 2014, MuleSoft Inc.21

How we build APIs

Add New Features/ Fix Bugs…

l All contents Copyright © 2014, MuleSoft Inc.22

How we build APIs

Add New Features/ Fix Bugs…

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.24

How we build APIs

Add New Features? What changed?

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.

It’s Broken.

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.

l All contents Copyright © 2014, MuleSoft Inc.

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.

What does it look like?

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.39

The RAML API Designer

l All contents Copyright © 2014, MuleSoft Inc.

Writing RAML

l All contents Copyright © 2014, MuleSoft Inc.

Writing RAML

Getting Started

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.

Writing RAML

Creating Resources

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.

Writing RAML

Schemas & Examples

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.

Writing RAML

ResourceTypes

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.

Writing RAML

Data Types

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.

Writing RAML

Libraries

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.

Writing RAML

Overlays

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.60

Do it Yourself

Get the Code at:

bit.ly/2aOiKzl

l All contents Copyright © 2014, MuleSoft Inc.

Community Tools

l All contents Copyright © 2014, MuleSoft Inc.

Community Tools

Design

l All contents Copyright © 2014, MuleSoft Inc.

API Workbench (offline)API Designer (online)

l All contents Copyright © 2014, MuleSoft Inc.

Community Tools

Build

l All contents Copyright © 2014, MuleSoft Inc.

Community Tools

Test

l All contents Copyright © 2014, MuleSoft Inc.

Community Tools

Document

l All contents Copyright © 2014, MuleSoft Inc.

RAML to HTML (Node.js)

l All contents Copyright © 2014, MuleSoft Inc.

RAML 2 HTML for PHP

l All contents Copyright © 2014, MuleSoft Inc.

Griffin by Spotify

l All contents Copyright © 2014, MuleSoft Inc.

Community Tools

Share

l All contents Copyright © 2014, MuleSoft Inc.

REST United

APIMatic.io

API Notebook

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.

One Final Thought

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.76

The Agile Design Cycle

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

l All contents Copyright © 2014, MuleSoft Inc.

THANK YOU!!!mulesoft.com/restbook

l All contents Copyright © 2014, MuleSoft Inc.

@MuleDevmulesoft.com/restbook