Learn MuleSoft from beginner to proficient (II) - Design API with RAML/RESTful Service

1. What is API Specification

An API Specification provides an understanding of how an API behaves.

  • What kind of request it accepts
  • What kind of response it returns
  • What are mandatory fields/data types, etc.

 

2. Design Center of Anypoint Platform

Design Center helps us to create API Specification in RAML(RESTful API Modeling Language).

It supports RAML by versions 0.8 and 1.

Core Elements:

  • Resource
    It is the unique name we give to identify a resource

  • Method
    GET, POST, PUT, DELETE, PATCH etc.

  • Request
    Body, queryparams, uriparams, headers, etc.

  • Http Status
    200, 201, 400, 404, 500, etc.

 

3. Design API

image.png


  • 3-2) Create new API specification
image.png
image.png
image.png

RAML Code:

#%RAML 1.0
title: session-2

/search:
  get:
    queryParameters:
      keyword:
        type: string
        minLength: 3
        maxLength: 10
    responses:
      200:
        body:
          application/json:
            example:
              {"message" : "result returned successful"}


  • 3-3) Mock API
image.png
image.png
  • 3-4) Make your API Spec public
image.png

Note: the copied public URL is the root, you should combined with your relative URL.
(eg: http://xxxx/xxx + /search?keyword=abc, http://xxxx/xxx is root URL you copied, /search?keyword=abc is your relative request URL)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容