API Design Concept
API Design Concept
Table of Contents
Table of Contents – 2
API and Services at Hub IT – API Design Concept
Table of Contents – 3
API and Services at Hub IT – API Design Concept
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 4
API and Services at Hub IT – API Design Concept
2 Introduction
This document shall help you to create decent APIs within the LH Group organization. It applies
to APIs created within the LH Group with full control over the API contents. If products are
incorporated which already offer APIs, this document is not applicable. There are a lot of
philosophical discussion on what is RESTful and what is good API Design. Let's keep the things
practical and stick to the rules below.
We are open for discussion, we aim at having some consistency on technical and design level
to ease creation and operation of APIs as well as their consumption.
Most of the concepts listed have been heavily inspired and sometimes blatantly copied from
existing resources, such as the API guidelines from Zalando and Adidas.
According to the LH Group architecture framework, this document is classified as a concept and
applies to all new projects and products developed within the Lufthansa Group.
Policy
• Introduction
o How to read this document
o Structure
• Core Principles
o Provisioning APIs
• API Design
• Consistency Fundamentals
• References and Hypertext
• API Security
• API implementation and development
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 5
API and Services at Hub IT – API Design Concept
2.2 Structure
This concept ist listing various aspects of API design and API development. Core Principles
provides some overarching and general concepts which MUST be followed. API Design
describes hints one SHOULD consider while defining and creating APIs. In Consistency
Fundamentals we list common behaviours and features of our APIs which in general MUST be
adhered.
API implementation and development provides hints for implementing an API specification.
All detail statements are listed using Heading5 paragraphs.
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 6
API and Services at Hub IT – API Design Concept
3 Core Principles
The core principles describe some basic features for API design at Lufthansa. They form the
main API Design and API Thinking basis together with some basic constraints.
3.2 Language
Any API content as well as documentation MUST use U.S. English language.
OpenAPI Specification
It is important to differentiate between an API description and an API implementation. The API
description forms the contract everybody can rely on and use as reference within their
respective tasks. An API description is valid for a set of resources/services grouped together.
Therefore an API MUST be described using the OpenAPI/Swagger specification. Version 2.0
MUST be used.
An API description MUST be put under version control.
An API description SHOULD be self contained an contain all information required to use the
API.
An API description SHOULD include examples which demonstrate how an API is used.
An API description MAY contain hints toward the business process and even note some
behavioural aspects. While this is often an implementation detail, in real life hints towards an
API boundaries, its behaviour and its quality attributes are useful information for the API
consumer.
Explanation of OpenAPI/Swagger format and information on how to create a API specification
document are available within document: API Spec - Swagger v2.0API Spec
3.3 Versioning
Versioning of API assets is REQUIRED. It allows all parties to understand how an API can be
used and how their relation to each other is.
There are at least three assets types which need to be versioned:
1. API Specification - the API Specification is the OpenAPI/Swagger file itself.
The API description in OpenAPI MUST use the title property. The title MUST be unique.
The API description in OpenAPI MUST use the version property with version parts:
major.minor.patch
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 7
API and Services at Hub IT – API Design Concept
o major version MUST remain stable for compatible changes. If an API's behaviour
changes, while the interface remains stable, the major version SHOULD be
updated or a new API resource name SHOULD be chosen.
o minor version MUST be updated for changes which are backward compatible.
o patch version MUST be updated if the specification is amended or extended, e.g
with examples or additional information. It MUST NOT be updated while the API
Implementation is patched.
The API description version SHOULD be updated accordingly to API design change.
2. API Implementation - the implementation referes to the code and configuration assetts,
which are in most cases version controled by a VCS.
An API Implementation supports an API Specification (aka Contract) either completely or
partly. A set of micro services might serve specific paths of an holistic API.
Provision of an API to the consumer is always based on the API specification and mediated
using middle-tier layers or service lookup strategies.
The API Implementation SHOULD use versioning parts: major.minor.patch.
o major version SHOULD remain stable for compatible changes
o minor version SHOULD be updated for changes which are backward compatible.
o patch version SHOULD be updated if the implementation is updated/patched, most
likely due to a bug fix.
3. API Route Configuration - this is implementation specific binding used within API Gateways
to connect an API published endpoint to and API implementation
APIs are provisioned on API Gateways. The configuration/binding within the API Gateway
wich binds the API contract to an API Implementation MUST be versioned.
Extenting APIs
When you are making a change to your API you SHOULD follow these rules for extending:
1. You SHOULD NOT take anything away
2. You SHOULD NOT change processing rules
3. You SHOULD NOT make optional things required
4. Anything you add SHOULD be optional
These set focus on retaining backward-compatibility.
Because of these rules the API surface should be kept at the minimum (once you introduce
something you cannot take it away). Likewise, the client must be liberal in what it accepts (e.g.,
ignoring anything it doesn’t understand — Postel’s law).
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 8
API and Services at Hub IT – API Design Concept
4 API Design
While designing new APIs, consider what value the API provides to the consumer. The API is a
managed product and the API provider needs to understand how this product will be used in
which context.
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 9
API and Services at Hub IT – API Design Concept
API Design MUST respect proper statehandling. REST requires statelessness (statelessness
constraint) when it comes to any server session state. In REST all state is self-contained and a
reference rather than depending on an external frame of reference. State is controlled by the
client and not inflected by any other means. This allows both scalability and channel
transparency, as state and state references is serializable.
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 10
API and Services at Hub IT – API Design Concept
Response :
HTTP/1.1 201 Created // 201 Created.
Location: /article/1234
Response :
HTTP/1.1 200 OK // 200 OK. (replaced red-stapler to blue-
stapler ( id remains same).
Location: /article/1234
Response :
HTTP/1.1 201 Created //201 Created.
Location: /article/green-stapler
Response :
HTTP/1.1 200 OK
Location: /article/green-stapler
or
PATCH /article/4321 HTTP/1.1 //PATCH Method to update partial
resource on existing record.
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 11
API and Services at Hub IT – API Design Concept
<article>
<price currency="eur">10.95</price> //price update for the green-
stapler or identifier 4321
</article>
Response :
HTTP/1.1 200 OK
Location: /article/4321
4.5 Content-Type
APIs SHOULD support application/json and MAY support application/xml
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 12
API and Services at Hub IT – API Design Concept
FlightNumber: {
Airline: "LH",
Number: "123"
}
FlightNumber: {
Airline: "LH",
Number: "123",
Suffix = "X"
}
curl -X POST \
https://api-test.lufthansa.com/v2/orders/transfer \
-H 'accept: application/json' \
-H 'authorization: Bearer xxx' \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-d '{
"FromFlights" : {
"FromFlight" : [ {
"Arrival" : {
"AirportCode" : "DUS"
},
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 13
API and Services at Hub IT – API Design Concept
"Departure" : {
"AirportCode" : "FRA",
"Date" : "2017-07-05"
},
"MarketingCarrier" : {
"AirlineID" : "LH",
"FlightNumber" : "4551"
},
"CabinType" : "C"
} ]
},
"ToFlights" : {
"ToFlight" : [ {
"Arrival" : {
"AirportCode" : "DUS"
},
"Departure" : {
"AirportCode" : "FRA",
"Date" : "2017-07-05"
},
"MarketingCarrier" : {
"AirlineID" : "LH",
"FlightNumber" : "4817"
},
"CabinType" : "C"
} ]
},
"FulfilmentObjectKey" : [ "FUFI_COP_SUCCESS_TEST71_1" ],
"OrderID" : "TEST71",
"Channel" : "BOT"
}'
{
"ObjectKey": "LH4551-FRA-20170705-FUFI_COP_SUCCESS_TEST71_1",
"FromFlights": {
"FromFlight": [
{
"Arrival": {
"AirportCode": "DUS"
},
"Departure": {
"AirportCode": "FRA",
"Date": "2017-07-05"
},
"MarketingCarrier": {
"AirlineID": "LH",
"FlightNumber": "4551"
},
"CabinType": "C"
}
]
},
"ToFlights": {
"ToFlight": [
{
"Arrival": {
"AirportCode": "DUS"
},
"Departure": {
"AirportCode": "FRA",
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 14
API and Services at Hub IT – API Design Concept
"Date": "2017-07-05"
},
"MarketingCarrier": {
"AirlineID": "LH",
"FlightNumber": "4817"
},
"CabinType": "C"
}
]
},
"FulfilmentObjectKey": [
"FUFI_COP_SUCCESS_TEST71_1"
],
"TransferStatus": "INITIALIZED",
"OrderID": "TEST71",
"Channel": "BOT"
}
curl -X GET \
https://api-test.lufthansa.com/v2/orders/transfer/LH4551-FRA-20170705-
FUFI_COP_SUCCESS_TEST71_1 \
-H 'accept: application/json' \
-H 'authorization: Bearer xxx' \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
{
"ObjectKey": "LH4551-FRA-20170705-FUFI_COP_SUCCESS_TEST71_1",
"TransferStatus": "SUCCEEDED",
"OrderID": "TEST71"
}
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 15
API and Services at Hub IT – API Design Concept
Consider JSON API - includes and JSON API - sparse field sets in your API to see if the
approaches are suitable.
(sources: API Design Guide; How to design a REST API)
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 16
API and Services at Hub IT – API Design Concept
5 Consistency Fundamentals
/v[0-9]+/domain/resourcePlural?filter=value
/v[0-9]+/domain/resourcePlural/{id}
GET /orders/first
200 OK
{"id":"1234", "state":"paid"}
GET /orders/last
200 OK
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 17
API and Services at Hub IT – API Design Concept
{"id":"5678", "state":"running"}
Following reserved word SHOULD be used to retrieve number of items within a collection:
Count
Use /count to get the current size of a collection
Code Block 11 /count
GET /orders/count
200 OK
{"2"}
Authorization Credential information. This item is required and checked at least on API
Gateway Level.
If-None- Provide the ETag from a previous request and expect 304 Not Modified
Match
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 18
API and Services at Hub IT – API Design Concept
Header Description
Date The date and time that the message was sent
Content-Type
Content-Encoding
Preference-Applied
ETag Include an ETag Header on cachable requests to mark the resource version
{
"requestIdentifier" → xsd:string,
"serviceHost" → xsd:string,
"processingErrors" → [
{
"processingError" → {
"retryIndicator" → xsd:boolean
"type" → xsd:string
"code" → xsd:integer
"description" → xsd:string
"infoUrl" → xsd:anyURI
"innerError" → {
"type" → xsd:string
"code" → xsd:integer
"description" → xsd:string
"innerError" → {
... optional inner errors ...
}
}
}
},
{
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 19
API and Services at Hub IT – API Design Concept
Exactly
one
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 20
API and Services at Hub IT – API Design Concept
{
"requestIdentifier" : "123456",
"serviceHost" : "lvm-inge-01ct",
"processingErrors": [
{
"processingError": {
"retryIndicator": false,
"type": "InputValidation",
"code": 3200,
"description": "Backend response not valid XML (This happens for
invalid cities or invalid date/time range).",
"infoUrl":
"http://api.lufthansa.com/errorcodes/{processingError.Code}"
"innerError": {
"code": 120,
"innerError": {
"code": 44567,
"description": "Exception in thread \"main\"
java.lang.NullPointerException at
com.example.myproject.Book.getTitle(Book.java:16)"
}
}
}
}
]
}
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 21
API and Services at Hub IT – API Design Concept
"Meta": {
"Link": [
"Href":
"https://api.lufthansa.com/v1/references/airports/{cityCode}",
"Rel": "related"
}]
}
"Meta": {
"Link": [{
"Href": "https:/references/airports/?offset=0&limit=20",
"Rel": "self"
}, {
"Href": "https:/references/airports/?offset=20&limit=20",
"Rel": "next"
}, {
"Href": "https:/references/airports/?offset=340&limit=20",
"Rel": "last"
}]
}
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 22
API and Services at Hub IT – API Design Concept
6.3 Filtering
At the end of the resource path the URL MAY include a query string for specification of filters
and options. This element of the standard URL structure is especially useful for providing
search parameters as well as operation options. If required, the elements MUST be created as
shown in the example: Acombination of simple filters applied for the “orders” resource could be
provided as follows:
orders?customerid={customerId}&type={type}&status={status}
This series of filters could be used to get all orders for a specified customer of a given type and
status.
This same format can be used to specify options for the resource operation, including both the
tag and the value for each option. For example, adding a setting for the “sortby” option to the
above URL:
orders?customerid={customerId}&type={type}&status={status}&sortby=date
This would indicate that the response should include all the orders fitting the filters, and that it
should also use the “date” for the “sortby” option. Some options might be commonly available,
whereas other options might be unique to a given resource and operation.
Whether for filters or options, the tags must be recognized by the web service, and the value
must be in an appropriate format. The available tags for filters and options, as well as the
expected formats for the values provided MUST be defined within the API Specifications.
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 23
API and Services at Hub IT – API Design Concept
7 API Security
(#TODO Security is an open Topic w. GI/X)
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 24
API and Services at Hub IT – API Design Concept
curl https://api.stripe.com/v1/charges \
-u sk_test_BQokikJOvBiI2HlWgH4olfQ2: \
-H "Idempotency-Key: AGJ6FJMkGQIpHUTX" \
-d amount=2000 \
-d currency=usd \
-d description="Charge for Brandur" \
-d customer=cus_A8Z5MHwQS7jUmZ
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 25
API and Services at Hub IT – API Design Concept
If the above Stripe request fails due to a network connection error, you can safely retry it with
the same idempotency key, and the customer is charged only once.
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 26
API and Services at Hub IT – API Design Concept
9.1 Summary
The following best practices describe how to implement the "API Design Concept” for the
Aspect "Provisioning of APIs". It describes technically which setup is implemented and can be
used to provision APIs via the LH OpenAPI and the LH MDW (ZAMBAS R6)
This document provides basic guidance, not in detail product setup and requires to refer to the
operational teams for OpenAPI and LHMDW for support.
9.2 Introduction
Policy
9.3 Scope
The practices herein aim at providing support on provisioning APIs on API Gateway solutions to
make them available for consumption by API consumers.
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 27
API and Services at Hub IT – API Design Concept
9.5.2 Throttling
An API provider SHOULD specify limitation for concurrent API access which will be used to
throttle the load on the server.
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 28
API and Services at Hub IT – API Design Concept
• On basis of a "consumer specific plan". A consumer specific plan is a special configured set
of APIs/Endpoints which is exclusivly assiged to one API consumer. It also can define
limits/throttles for each endpoint.
obelisk.dlh.de The resource proivider of a virtual name "obelisk.dlh.de" will be asked for
approval of the access rights.
The real DNS-name or IP address of the "obelisk.dlh.de" resource provider
differs from the scope's name in a regular case.
passengerList/read Forwarded 1:1 to the resource provider in the scope authorization request.
Of internal meaning to the "obelisk.dlh.de" service provider only.
9.5.4 Open API Gateway OAuth Scope and User Context support
Open API Gateway setup support OAuth with User Context and scope with OAuth Token
Providers for
• LH Crew Employees
• LH ID Customers
Open API Gateway resolves the access Token provided by API Consumer and forwards it as
header fields to the subsequent API Provider
Header field Content
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 29
API and Services at Hub IT – API Design Concept
X-Mashery- Header set by Mashery API Gateway resolving the bearer token to the stored
Oauth-Scope scope from OAuth2. If used, this scope header MUST be checked for valid
access roles within API implementation
X-Mashery- Header set by Mashery API Gateway resolving the bearer token to the stored
Userscope user-context value from OAuth2. This user-context MAY be used within API
implementation for logging or user information purposes
(#TODO JWT Token Header to be implemented, today OpenAPI GW forwards data as extra
header fields.)
ApplicationID A consumer application identifier. The Authorisation bearer token MAY contain
this information implicitly and the API Gateway will insert the field before calling
the downstream system
CallerID A consumer subsystem identifier. The Authorisation bearer token MAY contain
this information implicitly and the API Gateway might insert the field before calling
the downstream system
CallID A (unique) message ID. The API Gateway might insert the field before calling the
downstream system
CustomerID A multi tenant identifier. The Authorisation bearer token MAY contain this
information implicitly and he API Gateway might insert the field before calling the
downstream system.
9.7 Caching
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 30
API and Services at Hub IT – API Design Concept
{
"swagger": "2.0",
"info": {
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 31
API and Services at Hub IT – API Design Concept
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths" : {
// this section contains corresponding resources, descriptions,
request & response model references, request & response examples. refer
paths section below
},
"definitions" : {
//model of the API request & response schemas.
}
}
{
"swagger": "2.0",
"info": {
"version": "1.0.0", // for ex: "1.0-beta" or "1.1.2" etc.
"title": "LH Public Open API",
"description": "LH Open API - Users",
"termsOfService": "http://developer.lufthansa.com/terms/",
"contact": { //API suppor contact details
"name": "API Support",
"url": "https://developer.lufthansa.com",
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 32
API and Services at Hub IT – API Design Concept
"email": "api.support@dlh.de"
},
"license": {
"name": "LHG",
"url": "https://developer.lufthansa.com/licenses.html"
}
}
}
{
"swagger": "2.0",
....
"host": "api.lufthansa.com", //host or dns or IP/port
"basePath": "/v1", // common path across all resources : for
example : /v1 or "v1/api" or "v1/cargo" or "v1/passanger" etc . without
forward slash is incorrect for ex: "v2"
"schemes": [ // this section defines API to consume /
produce protocols for ex: https or http or both.
"https",
"http"
],
.....
}
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 33
API and Services at Hub IT – API Design Concept
tokenUrl string oauth2 ("password", Required. The token URL to be used for
"application", this flow. This SHOULD be in the form of
"accessCode") a URL.
{
"swagger": "2.0",
....
"securityDefinitions": {
"auth": {
"type": "oauth2",
"scopes": {
"read:LH Open API": "read access"
},
"flow": "accessCode",
"authorizationUrl": "https://api.lufthansa.com/v1/oauth/token",
"tokenUrl": "https://api.lufthansa.com/v1/oauth/token"
}
}
.....
}
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 34
API and Services at Hub IT – API Design Concept
{
"swagger": "2.0",
....
"consumes": [
"application/json", //define the MIME Types your application
supports for ex: xml, json, pdf, text etc. for both consumes or produces
section.
"application/xml"
],
"produces": [
"application/json",
"application/xml"
],
.....
}
10.6 Paths
paths are endpoints (resources) that your API exposes, such as /users or
/reports/summary, and operations are the HTTP methods used to manipulate these paths,
such as GET, POST or DELETE.
paths:
/ping:
...
/users:
...
/users/{id}:
...
path templats examples :
/users/{id}
/organizations/{orgId}/members/{memberId}
/report.{format}
Query String in Paths : Query string parameters must not be included in paths
GET /users?firstName=value&lastName=value
GET /users?role=value
Incorrect :
paths:
/users?role={role}:
Please refer link for more details on paths. the below section describes & contains most of the
infomration on paths.
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 35
API and Services at Hub IT – API Design Concept
{
"swagger": "2.0",
....
"paths": {
"/flightstatus/{flightnumber}/{date}": { //the path starts here &
support both POST & GET operations.
"get": {
"tags" : ["flightstatus"],
"summary": "Returns a list of flights by flightnumber & date.",
"description": "Optional extended description in Markdown.",
"operationId": "getflightsbyflightnumber"
"produces": "application/json",
"parameters" : [ ] //refer Parameter types section
"responses": {
"200": {
"description": "OK or Success",
"schema": {
"$ref": "#/definitions/schemas" // refer "deinitions"
section for more detials.
},
"examples" : {} //refer example section below for more
details.
}
}
}, //get opeation ends
"POST": {
"tags" : ["create flight infomration"],
"summary": "Returns a list of flights by flightnumber & date.",
"description": "Optional extended description in Markdown.",
"operationId": "getflightsbyflightnumber"
"produces": "application/json",
"parameters" : [ ], //refer below Parameter types section
"request" : {} , //refer below request section. this is valid for
all operations / methods (GET,"PUT","POST", DELETE).
"responses": {
"201": {
"name" : "Successfully created flight inforamtion"
"description": "OK or Success",
"schema": {
"$ref": "#/definitions/schemas" // refer "response
(output model) section" section for more detials.
},
"examples" : {} //response example.
}
}
} //POST opeation ends
}, // path end here.
//antoher new path can be added below
"/ping": {
...
},
"/users": {
...
},
"/users/{id}": {
...
}
}
....
}
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 36
API and Services at Hub IT – API Design Concept
{
"swagger": "2.0",
...."paths" : {
"/users/{username}" : {
"post" : {
"tags" : [ "create user" ],
"summary" : "create user",
"description" : "create user for given firstname, lastname,
username, emailaddress.",
"operationId" : "create user",
"produces" : [ "application/json", "application/xml" ],
"parameters" : [ {
"name" : "createuser",
"in" : "body", // this parameter "in" : "body" only
applicable for "POST" & "PUT".
"schema" : {
"$ref": "#/definitions/requestschema" //this is reference to
request schema & referred at end of swagger with "definitions" object
},
"examples" : {} //not allowed for POST, PUT & PATCH in swagger
v2.0.
},{
"name" : "username",
"in" : "path", // this paratmer is path parameter
/{username}
"description" : "username (unique)",
"required" : true,
"type" : "string",
"default" : "DK"
}, {
"name" : "emailaddress",
"in" : "query", // this parameter is for query parameter
for ex: /users/{username}?emailaddress=xyz@dlh.de
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 37
API and Services at Hub IT – API Design Concept
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 38
API and Services at Hub IT – API Design Concept
{
"swagger" : "2.0",
...
paths : {
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 39
API and Services at Hub IT – API Design Concept
}
}
}
}
}
}, //paths will end here.
....
"definitions" : { //this is definitions section defines more on the
request & resposne objects based on your application.
"requestschema" : {
"type": "object",
"properties": {
"createUserRequest" : {
"type" : "string"
}
}
},
"responseschema" : {
"type": "object",
"properties": {
"createUserResponse" : {
"type" : "string"
}
}
}
}
{
"swagger" : "2.0",
...
"/users/{username}" : {
"post" : {
"tags" : [ "create user" ],
"summary" : "create user",
"description" : "create user for given firstname, lastname,
username, emailaddress.",
"operationId" : "create user",
"produces" : [ "application/json", "application/xml" ],
"parameters" : [ {
//request, query, path paramters to define here.
}],
/* the below section is response structure for various status */
"responses" : {
"200" : {
"description" : "Successful Response",
"schema" : {
"$ref": "#/definitions/responseschema" //refer below
definitions block for schema definitions or model.
}
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 40
API and Services at Hub IT – API Design Concept
},
"400": {
"description": "Bad request. User ID must be an integer and
bigger than 0.",
"schema" : {
"$ref": "#/definitions/errorSchema" //refer below
definitions block for schema definitions or model.
}
},
"401": {
"description": "Authorization information is missing or
invalid.",
"schema" : {
"$ref": "#/definitions/errorSchema" //refer below
definitions block for schema definitions or model.
}
},
"404": {
"description": "A user with the specified ID was not found.",
"schema" : {
"$ref": "#/definitions/errorSchema"
}
}
} //end of responses block
}, //end of paths block
/* the below section definitions which defines the Model for request &
responses */
"definitions" : {
"requestschema" : { //request schema with simple string & more
infomration will be discussed in "Input & Output Models" section.
"type": "object",
"properties": {
"createUserRequest" : {
"type" : "string"
}
}
},
"responseschema" : { //response schema with simple string & more
infomration will be discussed in "Input & Output Models" section.
"type": "object",
"properties": {
"createUserResponse" : {
"type" : "string"
}
}
},
"errorSchema" : { //error schema referred for 400, 401, 404 resposne
codes.
"type": "array",
"items": {
"type": "array",
"items": {
"type": "array",
"items": {
"type": "object",
"properties": {
"ProcessingErrors": {
"type": "object",
"properties": {
"ProcessingError": {
"type": "object",
"properties": {
"@RetryIndicator": {
"type": "string",
"default": "false"
},
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 41
API and Services at Hub IT – API Design Concept
"Type": {
"type": "string",
"default": "InputValidation"
},
"Code": {
"type": "integer",
"default": 2202
},
"Description": {
"type": "string",
"default": "Invalid flight number in flight status
request (formally incorrect). Example: /flightstatus/LH400/2014-12-03."
},
"InfoURL": {
"type": "string",
"default": "not supported yet:
http://api.lufthansa.com/errorcodes/{processingError.Code}"
}
}
}
}
}
}
}
}
}
}
} //end of definitions
}
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 42
API and Services at Hub IT – API Design Concept
{
"swagger" : "2.0",
"responses" : {
"200" : {
"description" : "Successful Response",
"schema" : {
"$ref": "#/definitions/responseschema" //definitions
model will also contains the examples.
},
"examples": { //direclty mentioning the examples at
responses at method level but recommeded to use at definitions
//which helps in reusablity & no need to mention
the exampels for each method.
// swagger editor will not show the root element
while you mention the example at "responses".
// but the actual API response will contain the
root element "createUserResponse" tag.
"createUserResponse": {
"id": 38,
"title": "T-shirt"
}
}
},
Fehler! Verwenden Sie die Registerkarte 'Start', um Heading 1 dem Text zuzuweisen, der hier
angezeigt werden soll. – 43