I have been working lately on comparing on comparing different technologies to build web API’s.. One of the main concerns was if we wanted to build a simple API service which technology would be easier, more productive to develop the service with. To provide a reference comparison I will build the same web service (in MuleSoft, Azure Logic App, Asp.Net Core, Spring Boot) and provide my notes as I go. The web service would provide the following functionality
- CRUD operations on an Authors entity
- CRUD operations on BOOKS entities where books are related to authors
All the Read (queries) should support:
- Filtering
- Searching
- Paging
-
Supports Levels two and three in Richardson Maturity Model(see my previous post https://moustafarefaat.wordpress.com/2018/12/11/practical-rest-api-design-implementation-and-richardson-maturity-model/) . This means based on the Accept header of the request return the results as either:
- Pure JSON
- With HATEOUS
I will start with MuleSoft implementation.
Step 1. Define the API in RAML
With MuleSoft you get AnyPoint portal and you get the design center, which helps you designing the API RAML. There is API Designer visual Editor which can help you in the beginning.
Though it has many weakness such as:
- Once when you switch to RAML editor you cannot go back.
- You cannot define your own Media Types you have to use form the list.
To finalize the API definition in RAML I had to manually edit though the editor was helping to get started. Below is a fragment of the API in RAML (The full solution will be published on my GitHub https://github.com/RefaatM )
Notice in the RAML that I have defined two responses for the Get operation of the Authors Resources. Full RAML is at (https://github.com/RefaatM/MuleSoftRestAPIExample/tree/master/src/main/resources/api)
#%RAML 1.0
title: GTBooks
description: |
GTBooks Example
version: ‘1.0’
mediaType:
– application/json
– application/xml
protocols:
– HTTP
baseUri: /api/v1.0
types:
CreateAuthor:
description: This is a new DataType
type: object
properties:
Name:
required: true
example: Moustafa Refaat
description: Author Name
type: string
Nationality:
required: true
example: Canadian
description: ‘Author Nationality ‘
type: string
Date-of-Birth:
required: true
example: ‘2018-12-09’
description: Author Date of Birth
type: date-only
Date-of-Death:
required: false
example: ‘2018-12-09’
description: Author Date of Beath
type: date-only
Author:
description: This is a new DataType
type: CreateAuthor
properties:
Id:
required: true
example: 1
description: Author Id
type: integer
Age:
required: true
maximum: 200
minimum: 8
example: 10
description: Author Age
type: integer
AuthorHateoas:
description: Author with Hateoas information LINKS
type: Author
properties:
Links:
required: true
description: Property description
type: array
items:
required: true
type: Link
Link:
description: Hateoas LINK
type: object
properties:
href:
required: true
example: /Book/10
description: URL Link
type: string
rel:
required: true
example: GetBook
description: Operation
type: string
method:
required: true
example: GET
description: ‘HTTP Method Get, PUT,..’
type: string
/author:
get:
responses:
‘200’:
body:
application/json:
type: array
items:
type: Author
application/hateaos+json:
type: array
items:
type: AuthorHateoas
‘304’: {}
‘400’: {}
‘500’: {}
headers:
Accept:
example: ‘application/json ‘
description: application/json or application/hateaos+json
type: string
queryParameters:
sort-by:
required: false
example: Example
description: sort by
type: string
filteryby:
required: false
example: Example
description: Property description
type: string
(.. to be continued)