API Design Giude
API Design Giude
-Mule (3.x)
Revision History
1. To help formalize expectations and promote consistency within and outside of development team.
2. To provide additional information (i.e., metadata) about the use to which an identifier is put;
3. To enhance clarity in cases of potential ambiguity;
4. To provide meaningful data to be used in project handovers which require submission of program source code and all
relevant documentation
5. To reduce the effort needed to read and understand source code
6. To enable code reviews be able to focus on more important issues than arguing over syntax and naming standards.
7. To enable code quality review tools be able to focus their reporting mainly on significant issues other than syntax and style preferences.
8. To enhance source code appearance.
9. To provide better understanding in case of code reuse after a long interval of time.
Audience
This document is intended for
Development teams.
QA teams.
Deployment and Support teams.
Layer Identifier
Experience exp
Process prc
System sys
The domain Identifiers should be derived from the Enterprise Domain model; a short list is available below.
Domain
Please refer the enterprise business domain model. Below are some examples:
Customer
Restaurant
Marketing
Commerce
Sales
Technology
Sub-Domain
Please refer the enterprise business domain model. Below are some examples:
Accounts
Loyalty
Favorites
Application
Offer
Location
Order
Session
Feedback
Customer Master Data
Search
Purchase
People
Authentication
Content
Delivery
Music
Merchandise
URI Design
Best Practices
1. As a best practice and industry standard practice for RESTful style interfaces, the API resources should be named using nouns and
not verbs in their base URL. This practice is important because it helps to keep the total number of interfaces down; promotes a
consistent and easy to understand approach, and helps to encapsulate common functionality under a single resource.
Bad Good
/findStore /store/location
/deleteCustomer /customer
/object /store
2. The name of a resource should clearly describe the object or resource in which the backend service exposes. It is important to use the
right level of abstraction to clearly describe the resource that is being modelled in the context that it is being used. Adding a domain to
the URL path also helps to associate a resource with a specific logical domain.
Bad Good
/eCP/securityToken /security/token
/DEP/nutrition /product/nutrition
/object /store
3. Use proper methods to indicate the action, the following methods are recommended
a. GET
b. POST
c. PUT
d. PATCH
e. DELETE
4. While not a REST Standard, it is recommended to not use any variables in the URI. The recommended practice is to use the
query parameter for GET and DELETE and body for PUT, POST and PATCH
Bad Good
GET/customer/456/redemption GET/customer/customerid/redemption/?cutomerid=456
POST/restaurant/st5678/location POST/restaurant/storeid/location
{
{ "storied":"st5678"
"hello":"world" "hello":"world"
} }
Handling Actions
In REST, actions on a resource are implemented by the HTTP methods (GET/POST/PUT/DELETE) used when the web service is called.
These methods map to the CRUD model and dictate what actions to perform on the resource.
(C)reate POST
(R)ead GET
(U)pdate PUT or POST
(D)elete DELETE
For example, the \deleteCustomer from above can be implemented/mapped to a REST style API call using an HTTP DELETE to
the customer resource.
The delete URL would look something like this:
\customer?id=12345
The URL to read the customer record 12345 would look the same except it would be submitted as an HTTP GET request.
Parameters
Under REST there are several different ways to pass parameters to resources for a read & delete (HTTP GET & DELETE) request. To
maintain a consistent and an easy to understand approach, all parameters will be passed on the URL as a query string as a name/value
pair after the "?". For example:
/product/nutrition?id=12345
For insert and update (HTTP PUT & POST) will pass objects as JSON formatted documents in the body of the HTTP request. For
example:
{"id":"12345","name":"customer1"}
Lists can also be supported by passing in an array of JSON documents.
[{"id":"12345","name":"customer1"},{"id"="23456","name":"customer2"}]
Versioning
The endpoint URL for a service, which is the address that a consumer uses to locate and invoke a service, must reflect the major
version number only. This is because the inclusion of a minor version number would cause the address of the service to change for each
minor version release, thus making the service appear to have been removed, from an existing consumer's perspective.
The service's major version (prefixed with 'v') must be included in the endpoint URL of the address that consumers use to invoke the
service.
Example:
RAML
A RAML file is an integral part of an API, The RAML should be named with just the Service name.
<ServiceName>.raml
< ServiceName > is the name of the service for which this file is being created. E.g. Store
The version number of the file should not be included in the name, if needed version should be maintained as a comment
Example:
Example:
#%RAML 0.8
title: Store
baseUri:
http://api.na-org.com/\
{version}
version: v4
#fullVersion: v4.3.1
Mule project
Mule project are the basic building block and can be considered as the briefcase containing other mule artefacts like mule flows, RAML
files, schemas, sample request response json files and other connector specific libraries. Mule project names should be the same as
the service name. Avoid putting the version in the project name, it is best managed in the source control. Recommended to use all
lower case.
Mule flows
A Mule project can contain more than one flow or sub-flow. If project is generated using RAML file then each flow will have a default
name which is recommended to change. Hence each flow should be named as per the function it is going to perform. The flow can be
named with a verb (as per the HTTP method) followed by optional domain and the noun and then in the end will come the keyword 'Flow
For example:
Format Example
<verbDomainResourceFlow> getStoreLocationFlow
<verbResourceFlow> createCutomerFlow
If it is a sub-flow then flow keyword should be replaced with the SubFlow keyword keeping everything else same.
For Example:
getCustomerIdSubFlow
Recommended to use camel case.
Connectors
Mule flows will have connectors to connect with other applications. These connectors should be named as per the operations invoked
on the target system followed by the name of the target system separated by an underscore (_). It must not contain the protocol
information or implementation details of the connector. For example:
Format Example
<operationName_TGTSystemName> getCustomerInfo_CRM
<operationName_TGTSystemName> getStoreLocation_DB
Format Example
map<outputMessage> mapContactRequest
map<outputMessage> mapCustomerResponse
Variables
Mule has the variable, session variable and record variable components to set (create) or delete the variables in a flow. These variables
are used to keep the required data with them during the processing of the flow. Below are couple of rules that determine the naming of
a variable:
5. Variable name should not contain the numbers.
6. Variable name should not be abbreviated to the extent that it is hard to recognize the meaning of it. For example, a variable
containing customer id should not be named as CI while it can be named as custId or customerId.
7. It should be using the camel case notation.
8. It should be explanatory on what data it is holding. For example, customerDetails, storeName, itemId are all valid names.
Above points give us the naming patterns for the variables while components itself can be named as keyword 'set' followed by the variable nam
For example:
Format Example
<setVariableName> setCustomerId
<setVariableName> setOrderId
Property setContentTypeProperty
Logger logCustomerDetails
Appendix
Glossary
The following table lists the glossary of terms used in this document.
Acronym Description
Application A named entity which uses APIs for which proxies have been created and deployed in API Gateway.
Endpoint Refers to a location in either MuleESB or APIGateway which can receive incoming requests. Not all endpoints are accessible
from outside the application.In the API proxy case, endpoints are mostly HTTP/S."Endpoint" is often used as a term for a specific
"method" of an API.
Method Refers to a specific combination of:- relative URL (relative to the base-path of the API Gateway deployment- HTTP verb (GET,
PUT, POST, DELETE)
Component Mule has various visual components that perform a predefined operations depending upon the configuration done during design
time. A developer can select the desired component from the respective palette in IDE and can edit in the canvas (editable area).
These components are intertwined together to perform a business task.