Part-2-03-Communications Over HTTP Rest Draft v1.1
Part-2-03-Communications Over HTTP Rest Draft v1.1
The content (content being images, text or any other medium contained within this document which is
eligible of copyright protection) is Copyright © IFSF Ltd 2011. All rights expressly reserved.
You may print or download to a local hard disk extracts for your own business use. Any other
redistribution or reproduction of part or all of the contents in any form is prohibited. You may not,
except with our express written permission, distribute to any third party. Where permission to
distribute is granted by IFSF, the material must be acknowledged as IFSF copyright and the document
title specified. Where third party material has been identified, permission from the respective copyright
holder must be sought.
You agree to abide by all copyright notices and restrictions attached to the content and not to remove
or alter any such notice or restriction.
Subject to the following paragraph, you may design, develop and offer for sale products that embody
the functionality described in this document. No part of the content of this document may be claimed
as the Intellectual property of any organisation other than IFSF Ltd, and you specifically agree not to
claim patent rights or other IPR protection that relates to:
The content of this document; or
Any design or part thereof that embodies the content of this document whether in whole or
part.
This document was written by the IFSF – Device Integration Working Group. The latest revision of this
document can be downloaded from the Internet
Address: www.ifsf.org
3 DOCUMENT CONTENTS
1 COPYRIGHT AND INTELLECTUAL PROPERTY RIGHTS STATEMENT ..................................................... 3
2 DOCUMENT REVISION SHEET ........................................................................................................... 3
3 DOCUMENT CONTENTS .................................................................................................................... 4
4 REFERENCES ..................................................................................................................................... 5
5 GLOSSARY ......................................................................................................................................... 6
6 INTRODUCTION ................................................................................................................................ 8
6.1 BACKGROUND ............................................................................................................................. 8
6.2 WHAT IS REST? .......................................................................................................................... 8
6.3 ADVANTAGES AND DISADVANTAGES ................................................................................................ 9
7 IFSF RESTFUL REFERENCE ARCHITECTURE ........................................................................................ 9
7.1 CONTEXT DIAGRAM ...................................................................................................................... 9
7.2 COMPONENTS ........................................................................................................................... 10
7.3 SCOPE OF APPLICABILITY .............................................................................................................. 10
7.4 CRITERIA FOR IFSF RESTFUL API.................................................................................................. 11
7.5 SAFETY AND IDEMPOTENCE.......................................................................................................... 12
7.6 HTTP VERBS............................................................................................................................. 12
7.7 URL FORMAT, NAMING CONVENTION AND VERSIONS ...................................................................... 13
7.8 EXPOSING SEVERAL API VERSIONS ................................................................................................. 13
7.9 HTTP HEADERS ......................................................................................................................... 14
7.10 HTTP STATUS CODES ................................................................................................................. 14
7.11 ERROR HANDLING ...................................................................................................................... 14
7.11.1 Success .............................................................................................................................. 14
7.11.2 Functional errors ............................................................................................................... 15
7.11.3 Technical errors ................................................................................................................. 16
7.11.4 Detailed information about errors ..................................................................................... 16
7.12 CONTENT-TYPE .......................................................................................................................... 17
7.13 DATA ENCODING ....................................................................................................................... 17
7.14 CACHING .................................................................................................................................. 17
8 NETWORK AND NETWORK SECURITY .............................................................................................. 18
8.1 PROXIES ................................................................................................................................... 18
8.2 FIREWALL ................................................................................................................................. 18
8.3 TRANSPORT-LAYER SECURITY ........................................................................................................ 18
8.3.1 Certificate Management ....................................................................................................... 19
9 APPLICATION AUTHENTICATION AND AUTHORIZATION ................................................................. 21
9.1 DECOUPLING AUTHENTICATION AND AUTHORIZATION FROM APIS ..................................................... 21
9.2 USING NO AUTHENTICATION ........................................................................................................ 22
9.3 USING USER AND PASSWORD TO AUTHENTICATE USERS ................................................................... 22
9.4 USING API KEYS TO AUTHENTICATE ACCESS ................................................................................... 23
9.5 USING OAUTH2.0 TO AUTHENTICATE API KEYS ............................................................................... 25
9.5.1 Encoding consumer key and secret........................................................................................ 25
9.5.2 Obtain a bearer token ........................................................................................................... 26
9.5.3 Authenticate API requests with a bearer token ..................................................................... 27
10 USE-CASES ............................................................................................................................. 27
10.1 ACCESSING A RESOURCE .............................................................................................................. 27
10.2 QUERIES AND FILTER................................................................................................................... 28
10.2.1 Get a resource since the unique identifier ......................................................................... 28
10.2.2 Get a resource since a unique field, different to the unique identifier ............................... 28
10.2.3 Get a resource (or a set of resources) using a combination of fields ................................. 29
10.3 SORTING RESULTS ...................................................................................................................... 30
10.3.1 Client side .......................................................................................................................... 30
10.3.2 Server side ......................................................................................................................... 30
10.4 BULK OPERATIONS...................................................................................................................... 30
10.5 PAGING THE RESULTS .................................................................................................................. 31
10.6 ASYNCHRONOUS CALLS ............................................................................................................... 33
11 REST BACKWARDS COMPATIBILITY ........................................................................................ 34
4 References
[1] IFSF STANDARD FORECOURT PROTOCOL PART II – COMMUNICATION SPECIFICATION
[2] IFSF STANDARD FORECOURT PROTOCOL PART III.I – DISPENSER APPLICATION
[3] Microsoft Developer Network (MSDN) Helps
[4] The Internet Engineering Task Force (IETF®)
[5] Guidelines for Implementation of REST - National Security Agency (NSA)
[6]
[7] HTTP Digest AKAv2 RFC 4169: https://www.ietf.org/rfc/rfc4169.txt
[8] Baseline Requirements Certificate Policy for the Issuance and Management of Publicly-
Trusted Certificates
https://cabforum.org/wp-content/uploads/Baseline_Requirements_V1_3_1.pdf
5 Glossary
Internet The name given to the interconnection of many isolated networks into a virtual
single network.
Service A process that accepts connections from other processes, typically called client
processes, either on the same computer or a remote computer.
Socket The combination of the IP address, protocol (TCP or UDP) and port number on a
Address computer that defines the complete and unique address of a socket on a computer
IFSF heartbeat The UDP port to be used by all IFSF compliant devices having been assigned by the
port Internet Assigned Numbers Authority (IANA) as '3486'.
API Application Programming Interface. An API is a set of routines, protocols, and tools
for building software applications
CHP Central Host Platform (the host component of the web services solution)
EB Engineering Bulletin
FP (IFSF) Fuelling Point (in customer terminology the common name is “pump number”)
JSON JavaScript Object Notation; is an open standard format that uses human-readable
text
to transmit data objects consisting of attribute-value pairs
URL Universal Resource Locator. The most common form of URI is the uniform resource
locator (URL), frequently referred to informally as a web address.
XML Extensible Markup Language is a markup language that defines a set of rules for
encoding documents in a format which is both human-readable and machine-
readable
6 Introduction
This document describes the transport of IFSF application messages using HTTP RESTful services. IFSF
message details are described in each corresponding application specification. For the user to quickly
identify REST implementations from current specifications, all REST documents will be identified within
Part 4.
Representational State Transfer (REST) is a software architecture style for building scalable web
services. REST gives a coordinated set of constraints to the design of components in a distributed
hypermedia system that can lead to a higher performing and more maintainable architecture.
RESTful systems typically, but not always, communicate over the Hypertext Transfer Protocol with the
same HTTP verbs (GET, POST, PUT, DELETE, etc.) which web browsers use to retrieve web pages and to
send data to remote servers.
6.1 Background
Representational State Transfer (better known as REST) is a programming philosophy that was
introduced by Roy T. Fielding in his doctoral dissertation at the University of California, Irvine, in 2000.
Since then it has been gaining popularity and is being used in many different areas. Perhaps the best
description of REST is from Roy Fielding himself:
Representational State Transfer (REST) is an architectural principle rather than a standard or a protocol.
The basic tenets of REST are: simplify your operations, name every resource using nouns, and utilize
the HTTP commands GET, PUT, POST, and DELETE according to how their use is outlined in the original
HTTP RFC (RFC 26163). REST is stateless, does not specify the implementation details, and the
interconnection of resources is done via URIs. REST can also utilize the HTTP HEAD command primarily
for checking the existence of a resource or obtaining its metadata.
• Every resource and interconnection of resources is uniquely identified and addressable with a
URI [consistency advantage]
• Only four HTTP commands are used (HTTP GET, PUT, POST, DELETE) [standards compliance
advantage]
• Data is not passed, but rather a link to the data (as well as metadata about the referenced data)
is sent, which minimizes the load on the network and allows the data repository to enforce and
maintain access control [capacity/efficiency advantage]
• Can be implemented quickly [time to market advantage]
• Short learning curve to implement; already understood as it is the way the World Wide Web
works now [time to market advantage]
• Intermediaries (e.g. proxy servers, firewalls) can be inserted between clients and resources
[capacity advantage]
• Statelessness simplifies implementation – no need to synchronize state [time to market
advantage]
• Facilitates integration (mashups) of RESTful services [time to market advantage]
• Can utilize the client to do more work (the client being an untapped resource)
• Servers and clients implementing/using REST are vulnerable to the same threats as any
HTTP/Web application
• If the HTTP commands are used improperly or the problem is not well broken out into a RESTful
implementation, things can quickly resort to the use of Remote Procedure Call (RPC) methods
and thus have a nonRESTful solution
• REST servers are designed for scalability and will quickly disconnect idle clients. Long running
requests must be handled via callbacks or job queues.
• Porting the IFSF Unsolicited Messages mechanism to REST is not trivial. The client must have a
reachable HTTP(S) server and a subscription mechanism is necessary.
IFSF REST Services exposes CHP services to the Site systems (and vice versa). Site systems must send
the following requests in order to exchange information with a central host platform.
1. POST IFSF Site Data (e.g. Tank stock data, Tank sales data, Tank deliveries data, sales
transaction)
2. GET IFSF Site Data (e.g. Fuel Name, Fuel Price)
3. PUT IFSF Site Data (e.g. overwrite the current tank status (e.g. high water alarm, out of stock))
4. DELETE IFSF Site Data (e.g. remove equipment record from site as no longer present)
The REST services exposed are shown in the diagrams below. The first Figure are those exposed by the
Central Host Platform and the second are those exposed by the Site System.
7.2 Components
From an equipment scope perspective, this specification applies to all the components of a IFSF
systems, and the interrelation between several system of a IFSF ecosystem. From a communications
perspective, this specification covers communications between site systems and Central Host
Processors (CHPs), and between CHP applications.
Although not covered in this specification, future releases of this document might cover
communications within site systems. To cover intra site systems communications, additional features
such a discovery services will need to be included in this specification.
In order to design the IFSF REST-ful API, the following principles are applied:
• Short (as possible). This makes them easy to write down, spell, or remember.
• Hackable ‘up the tree’. The consumer should be able to remove the leaf path and get an
expected page back. e.g. http://mycentralremc.com/sites/12345 you could remove the 12345
site ID identifier and expect to get back all the site list.
• Meaningful. Describes the resource. I should have a hint at the type of resource I am looking at
(a blog post, or a conversation). Ideally I would have a clue about the actual content of the URI
(e.g. a uri like uri-design-essay)
• Predictable. Human-guessable. If your URLs are meaningful, they may also be predictable. If
your users understand them and can predict what a URL for a given resource is then may be
able to go ‘straight there’ without having to find a hyperlink on a page. If your URIs are
predictable, then your developers will argue less over what should be used for new resource
types.
• Readable.
• Nouns, not verbs. A resource is a noun, modified using the HTTP verbs
• Query args (everything after the ?) are used on querying/searching resources (exclusively).
They contain data that affects the query.
• Consistent. If you use extensions, do not use .html in one location and .htm in another.
Consistent patterns make URIs more predictable.
• Stateless.
• Return a representation (e.g. XML or JSON) based on the request headers. For the scope of IFSF
REST implementation, only JSON representations will be supported.
• Tied to a resource. Permanent. The URI will continue to work while the resource exists, and
despite the resource potentially changing over time.
• Report canonical URIs. If you have two different URIs for the same resource, ensure you put
the canonical URL in the response.
• Follows the digging-deeper-path-and-backspace convention. URI path can be used like a
backspace.
• Uses name1=value1;name2=value2 (aka matrix parameters) when filtering collections of
resources.
• Use a plural path for collections. e.g. /sites.
• Put individual resources under the plural collection path. e.g. /sites/123456. Although some
may disagree and argue it be something like /123456, the individual resource fits nicely under
the collection. It also allows to ‘hack the url’ up a level and remove the siteID part and be left
on the /sites page listing all (or some) of the sites.
• The definitions of the URIs will follow the IETF RFC 3986 (https://www.ietf.org/rfc/rfc3986.txt)
that define an URI as a hierarchical form.
A few key concepts to understand before implementing HTTP methods include the concepts of safety
and idempotence.
A safe method is one that is not expected to cause side effects. An example of a side effect would be a
user conducting a search and altering the data by the mere fact that they conducted a search (e.g. if a
user searches on “blue car” the data does not increment the number of blue cars or update the user’s
data to indicate his favourite colour is blue). The search should have no ‘effect’ on the underlying data.
Side effects are still possible, but they are not done at the request of the client and they should not
cause harm. A method that follows these guidelines is considered ‘safe.’
The importance of safety and idempotence is that it allows users to use HTTP and know that their
actions will not change the underlying resource. Of course, this is dependent on uniform usage of the
four HTTP verbs. REST relies heavily on this uniform usage so that there are no unintended
consequences or unexpected actions. Without a uniform interface, each resource would require a
custom interface that understands how that resource expects to send and receive information. This
would undermine one of the main goals of REST – simplicity and ease of use.
The key point to remember is that in order to ensure that an operation / implementation is RESTful,
these methods must be used as they were defined in RFC 2616, the HTTP 1.1 specification. If
implementations abuse these methods, they not only depart from RESTful behaviour, but also
jeopardize the application’s ability to interoperate with other RESTful capabilities.
HTTP defines many verbs, applicable in the Internet world. REST API is a subset of the internet world,
so it not apply all the HTTP verbs, but just four as a minimum, 5 as a maximum.
The next table summarises the IFSF APIs accepted verbs. This point is strict and the use of others verbs
will not be allowed.
any side effects due to its use, in other words it should be used in a safe
and idempotent manner.
Creates the representation of a new resource into a collection. A
POST -/- collection is a set of resource representations. The representation of the
new object is transferred using the body of the HTTP request,
Updates a representation of an existing resource. The body of the request
represent the new state of the representation of a given resource. PUT
PUT -/I
should only be used to create new resources only when clients can decide
URIs of resources (otherwise use POST).
Deletes a given resource instance. The representations of the resource
DELETE -/I will be no longer available after the execution of a DELETE operation.
Responses to the DELETE method are not cacheable.
A URL (Uniform Resource Locator) is the way you may identify a resource in a network. In the case of
the IFSF API’s, the URL will identify a resource provided by a computer system, which will be consumed
by other computer systems. In the context of this document, the RESTful approach defines an API as a
bundle of resources well defined, and uniquely identified. Some examples of resources could be
Country, User or Dispenser.
In order to support several client releases consuming different API versions, a server can expose
multiple versions of the same API.
For example,
http://api.ifsf.org/ifsf-fdc/v2/sites
http://api.ifsf.org/ifsf-fdc/v2.01/sites
The IFSF will use only the standard HTTP headers for its API, and only the following Headers:
● Accept, to negotiate the representations of a resource, and the version of the referenced
resource.
● Accept-language: to negotiate the language of the representation of a resource (for
internationalization). If this header is not specified, the application will respond in its default
implementation language.
● Authorization: to manage the authentication and authorization of a user and application to a
given resource.
● Accept-encoding: Used to compress server response.
● Cache-Control: Used to direct proxy servers not to cache responses
● Content-type: to inform the representation of a query or a response.
As said previously, RESTful APIs works over HTTP, and an important part of HTTP are the status codes,
which represent the status (success or failure) of the request and interchange of information between
the parties.
The following section summarises the HTTP status codes used by IFSF APIs:
There will be three types of situations when a client performs a request to a server that will be managed
in different ways
7.11.1 Success
This type are related with errors or mistakes not produced by the server itself, and not related with
technical issues, but related to functional validations or client request mistakes.
In case of errors, the following status code will be returned:
Business rule
490 Reserved for business validations.
conflict
Technical errors are situations non-handled or unexpected in the server side. The code used to inform
this situation are the following:
The functional or technical errors described previously, will have a detailed description, defined as a
JSON object as a response, with the following structure:
• Error code: a unique identifier of the error. Each IFSF application communication standard must
define its error code catalog.
• Reference ID: Optional server side error identifier. Client must support receiving the value.
• User message: A message for end-user usage.
• Technical message: A message for technical usage, with more information.
• Stack Trace: Optional stack trace information for debugging purposes.
• Error code links: a link point to more information about the error (optional).
{
“errorCode”: 146,
“referenceId”: 4584050844,
“userMessage”: “Error saving your data!!!”,
“technicalMessage”: “Error saving into Tank, duplicated ID”,
“stackTrace”:”java.lang.NullPointerException
pump.presentation.controllers.UnixServerJobController.handleRequest(UnixServerJ
obController.java:66)
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(Sim
pleControllerHandlerAdapter.java:48)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(Character
EncodingFilter.java:96)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilte
r.java:76)”,
“errorCodeLink”: ”http://developers.ifsf.com/errors/146”
}
7.12 Content-type
The IFSF API use the Media Type standard to define the types of representations of a resource, and the
HTTP headers Accept and Content-type to communicate the types of representation between parties.
The IFSF API accepts application/json only, but it would be possible to extend it in the future to other
media types such as application/xml.
For example, to get the list of tanks in a site (e.g. with 12345 as identifier) in JSON, a user must use the
following command:
Request:
GET http://api.ifsf.org/ifsf-remc/v1/sites/8652345
Accept: application/json
Response:
HTTP 200 OK
Content-type: application/json
{
"Site": {
"id": "8652345",
"name": "Wimbledon",
"type": "COCO",
"address": "7 Privet Drive Wimbledon",
"country": "UK",
}
}
The IFSF API use compression to reduce the bandwidth requirements of the communication. Both
parties must support gzip encoding. The development parties can add other encoding schemes, but
every API must support at least gzip.
For example, the following request requires compression of the results in gzip format:
Request:
GET http://api.ifsf.org/ifsf-remc/v1/sites/8652345
Accept-Encoding: gzip
7.14 Caching
This document is Intellectual property of IFSF
Revision / Date: Page:
PART 2.03 COMMUNICATIONS SPECIFICATIONS OVER REST
Vers. 1.1 (DRAFT) / Dec.2016 18 of 34
The IFSF API must ensure that information is not cached in intermediate servers and that the client will
always receive the current response from the server.
Request:
GET http://api.ifsf.org/ifsf-remc/v1/sites/8652345
Cache-Control: no-cache
As with any networking environment, security measures should be implemented in line with the results
of risk assessment for a given installation. Details are dependent on the network installation and hence
our outside the scope of this document. However, the following items should be considered.
IFSF is not responsible for auditing security during the certification process. It is up to the
implementation team to make sure that security is consistent with standards at the time of
implementation and are properly kept up to date during the product life cycle.
8.1 Proxies
A proxy server is a server that sits between a client and server. A proxy is mostly transparent to end-
users, so you think you are sending HTTP request messages directly to a server, but the messages are
actually going to a proxy.
• Proxies can perform a wide range of one or more services. The following paragraphs highlight
a few of the popular services.
• Load balancing proxies can take a message and forward it to one of several web servers on a
round-robin basis, or by knowing which server is currently processing the fewest number of
requests.
• SSL acceleration proxies can encrypt and decrypt HTTP messages, taking the encryption load
off a web server.
• Proxies can provide an additional layer of security by filtering out potentially dangerous HTTP
messages. Specifically, messages that look like they might be trying to find a cross-site scripting
(XSS) vulnerability or launch a SQL injection attack.
• Caching proxies will store copies of frequently access resources and responding to messages
requesting those resources directly.
8.2 Firewall
TLS must be supported by all parties, although it can be disabled during implementation. Whenever TLS
is active, the following rules must be observed:
TLS version: servers and clients MUST support TLS 1.2. SSL 2.0, SSL 3.0, TLS 1.0 and TLS 1.1 are
forbidden. TLS 1.3 is currently in draft, so it is not considered.
Key exchange: servers and clients MUST support DHE-RSA (forward secrecy), which is part of both TLS
1.2 and TLS 1.3 draft.
Block Ciphers: servers and clients MUST support AES-256 CBC. DES, 3DES, AES-128 and AES192 are
forbidden.
Data integrity: servers and clients MUST support HMAC-SHA256/384. HMAC-MD5 and HMAC-SHA1 are
forbidden.
Vendors are allowed to support other TLS/key exchange/cipher and MAC algorithms.
Certificates signed using MD5 or SHA1 must be not be trusted. All vendors MUST support certificates
signed using SHA2. Self-signed certificates are allowed.
Vendors MUST provide mechanisms for authorized users and technicians to disable security algorithms
in order to keep up with security industry recommendations. As reference for vulnerability publications,
please refer to:
Each equipment should provide a documented means of loading certificates to connect to other
applications, as well as to provide a certificate for other applications to connect. The following functions
must be covered:
• Adding a root or intermediate certificate to connect to the certificate store.
• Revoking a certificate
• Connect to one or more external certificate providers. This will give a company the possibility
to centrally manage equipment certificates.
Implementation details for these functionalities are responsibility of each equipment manufacturer but
should be documented for certification.
The client systems MUST support both Online Certificate Status Protocol (OCSP) and Certificate
Revocation List (CRL) for online certificate verification. In case of CRL repository or OCSP Server not
being available, the implementer should be capable of determining if soft fail (assume the certificate
has not being revoked) is allowed or not.
At the time of writing, CRLSet as proposed by Google for CRL distribution and offline certificate
verification is still not mature enough to be included in this standard.
Additionally, any IFSF compliant API may implement OAuth 2.0 for delegation of authentication
functions. This will enable that access to all APIs be managed centrally in the future. Although not
mandatory, applications connecting to a REST API are recommended to support API keys authentication
over OAuth 2.0 architecture, as APIs security can be enhanced to support OAuth security through third
party application packages.
Note: Using digest methods to secure user and password is not recommended, as using TLS will provide
better levels of security, with better encryption keys management processes.
To provide a higher level of security and implementing advanced security features while keeping
security implementation and management processes unified for all implemented APIs, the
implementer can deploy a central security management application.
There are off the shelf API manager software applications that can provide security services, including:
OAuth security
Token based security
End to end encryption with TLS
Rate limiting
Centralized administration
Monitoring tools
Revocation policies, etc.
Currently there are both open source and enterprise grade applications that provide these
functionalities.
An API manager software application adds security to an unsecured API by exposing new secured
endpoints to API clients and, once properly authorized, forwarding the request to the unsecured API,
as depicted in the figure below:
Note: Although the API manager can add security to an unsecured API, it will not resolve the injection
of security into the client.
Implementing advanced security features within APIs is not recommended due to:
Software development complexity
o Cost of development
o Time of implementation
o Need of specialized development professionals
o High testing complexity
o High certification complexity
Cost of Support over a large variety of systems.
Permanent need to update security to keep up to date throughout time.
o Security algorithms are permanently deprecated due to detected vulnerabilities (E.G.
DES)
The implementing parties can optionally disable all authentication methods, hence providing access
with no authentication whenever the implementer deems it unnecessary, as the infrastructure is
already secure, or if they delegate access authentication and authorization to an external application
as explained above.
To request access using a user and password combination, the client application must include in the
header a string containing user and password separated by a colon encoded in base64. Base64
encoding will not provide any level of encryption. Encryption can be achieved by using TLS 1.2 as
recommended in the part 2.3 standard document.
Example request:
Username= “IFSFClient”
Password= “pleaseGiveMeAccess”
Access Token: BASE64 ("IFSFClient:pleaseGiveMeAccess”):
SUZTRkNsaWVudDpwbGVhc2VHaXZlTWVBY2Nlc3M=
Submitted request:
POST /ifsf-fdc/v2/sites
Host: api.ifsf.org
Authorization: Basic SUZTRkNsaWVudDpwbGVhc2VHaXZlTWVBY2Nlc3M=
Content-Type: charset=UTF-8
Body Payload
To request access using an API KEY, the client application must include in the header a string containing
the API key value. Base64 encoding is not required in this case, as API keys are designed not to require
encoding. As in the case of basic security, encryption can be achieved by using TLS 1.2 as recommended
in the part 2.3 standard document.
Note: Moving the API Key into the Authentication header works around allows much more efficient
caching. The HTTP Spec states that, "A shared cache MUST NOT use a cached response to a
request with an Authorization header field (Section 4.1 of [Part7]) to satisfy any subsequent
request unless a cache directive that allows such responses to be stored is present in the
response". This will avoid cache servers sending the same response to other applications, unless
the response contains the following directive: Cache-Control: public, enforcing cache servers
to cache the response for further API clients.
Example request:
Submitted request:
POST /ifsf-fdc/v2/sites
Host: api.ifsf.org
Authorization: apikey IFSFClientAbc123
Content-Type: charset=UTF-8
Body Payload
API Keys over Oauth2.0 can be used to authenticate communications between equipment.
The API key will perform application only authorization. When using API key authorization please keep
in mind the following:
The steps to encode an application’s consumer key and secret into a set of credentials to obtain a
bearer token are:
• URL encode the consumer key and the consumer secret according to RFC 1738. Note that at
the time of writing, this will not actually change the consumer key and secret, but this step
should still be performed in case the format of those values changes in the future.
• Concatenate the encoded consumer key, a colon character “:”, and the encoded consumer
secret into a single string.
• Base64 encode the string from the previous step.
The value calculated in previous step must be exchanged for a bearer token by issuing a request to
POST oauth2 / token:
grant_type=client_credentials
If the request format is correct, the server will respond with a JSON-encoded payload:
Example response:
HTTP/1.1 200 OK
Status: 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 140
{"token_type":"bearer","access_token":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAA%2FAAAAAAAAAAAAAAAAAAAA%3DAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAA"}
Applications should verify that the value associated with the “token_type” key of the returned object
is bearer. The value associated with the “access_token” key is the bearer token.
The bearer token may be used to issue requests to API endpoints that support application-only auth.
To use the bearer token, construct a normal HTTPS request and include an Authorization header with
the value of Bearer <base64 bearer token value from step 2>. Signing is not required.
Example request (Authorization header has been wrapped):
10 Use-cases
10.1 Accessing a resource
The following use cases present some examples on how to invoke REST services.
To get the settings of a given country (e.g. UK), the following command could be used:
GET http://api.ifsf.org/ifsf-wsm/v1/countries/UK/settings
The command above will return a representation of the settings for UK.
Now, to update the settings of a given country (e.g. UK), the following command could be used:
PUT http://api.ifsf.org/ifsf-wsm/v1/countries/UK/settings
The command above will update the representation of the settings for UK. The new representation will
be transferred through the HTTP Body.
An IFSF compliant API should expose the information of the resource through GET HTTP verb, enabling
the client to include queries and filters.
Although query and filtering are more related to collections, there are three possible scenarios about
searching, detailed next.
In this scenario, the clients need to get the representation of a resource, and he knows its unique
identifier.
In order to cover this use case, an IFSF compliant API should accept the unique identifier of a resource
as part of the URL, as expressed in the following example:
GET http://api.ifsf.org/ifsf-fdc/v1/sites/12345
This example will return the representation of the site which unique identifier is 12345.
10.2.2 Get a resource since a unique field, different to the unique identifier
Sometimes it may happen that the client does not know the unique identifier of a resource, but knows
the value of another field, that also uniquely identifies the resource. In this use case, the API should
accept a filter as a parameter in the querystring.
In the following example, the client does not know the unique identifier of a site (that is generated
internally for the host system), but knows the canonical name (field name) of the site (given by the
company, and known by everybody). This canonical name is unique among all sites, so it identifies
uniquely each one.
GET http://api.ifsf.org/ifsf-fdc/v1/sites?name=Raymond
This example will return a set containing a single element corresponding to the representation of the
site, with a canonical name (field name) of “Raymond”. The response is slightly different to the previous
use case where the client queries the element instead of the collection.
The first and second scenarios was focused on getting a resource, but the most common use case is
querying for a set or resources, filtering its result using a set of parameters.
In this use case, the client of the API know some data about the resource, but not everything
(sometimes a functional category, the region to which a resource belongs, or another field).
The API, in order to cover this scenario, should accept a set of parameters as key-value pairs in the
query string, and should use it to filter the resultset.
To exemplify this case, we will suppose the site resource contains the attributes name, zone, company
and averageSalesAmount.
Given this resource, to get all the sites located in the zone “Boston”, and that belong to the company
“XYZ”, a client should use the following command:
GET http://api.ifsf.org/ifsf-fdc/v1/sites?zone=Boston&company=XYZ
The above cases only applies when the client needs to filter by an exact value, or a set of exact values.
If a client needs to get resource comparing a field with another operator different as equal (e.g. greater
than or less than), the API should accept an additional parameter following each filter name - filter value
pairs, called “op”, that will determine the comparison. The operators will be:
● LT, for “less than”
● GT, for “greater than”
● LET, for “less or equal than”
● GET, for “greater or equal than”
● EQ, for “equal”
Following the previous example, if a client should know the sites of the zone “Boston” that sell more
than 100.000 Pounds (field averageSalesAmount) greater than 100000, should use the following
command:
GET http://api.ifsf.org/ifsf-fdc/v1/sites?zone=Boston&averageSalesAmount
=100000#&op=GT
The client consumes an API, receiving the result set and sorting locally on the client-side. This is not
always an option since sorting may require significant resources (memory, processor, storage) that are
not available at the client side.
If an API designer wishes to offer a sorting mechanism, the API call MUST use the “sort” query
parameter. A list of comma separated fields can be specified in the criteria. The default sort order is
ascending. Descending sort order is indicated by a ‘-‘ field prefix.
For example, in the following request a client asks for the tank list for site 12345 sorted by product
ascending and by current volume descending:
If an API designer wishes to offer bulk operations for creation, deletion or update of multiple resources,
the server must be prepared to process the request operation asynchronously, following the rules set
forth in the “Asynchronous Calls” section.
For example, if a client should create 3 sites, the command could be the following:
POST http://api.ifsf.org/ifsf-fdc/v1/sites
sites = [
{
“Zone”:”1”,
“Company”:”AAA”,
“name”:”Raymond”,
“averageSalesAmount”:”10000”,
“pbl”:”13579”
},
{
“Zone”:”1”,
“Company”:”AADA”,
“name”:”Twickenham”,
“averageSalesAmount”:”80000”,
“pbl”:”22222”
},
{
“Zone”:”1”,
“Company”:”AABBA”,
“name”:”Wimbledon”,
“averageSalesAmount”:”110000”,
“pbl”:”12345”
}
]
NOTE: Bulk operations should only be accepted when the command is specified to support this way
of processing in the application documentation.
Some IFSF API requests might offer results paging. The way to include pagination details is using the
Link header introduced by RFC 5988.
For example
GET http://api.ifsf.org/ifsf-fdc/v1/sites?zone=Boston&start=20&limit=5
The response should include pagination information in the Link header field as depicted below
{
“start”: 1,
“count”: 5,
“totalCount”: 100,
“totalPages”: 20,
“links”: [
{
“href”: “http://api.ifsf.org/ifsf-fdc/v1/sites?zone=Boston&start=26&limit=5”,
“rel”: “next”
},
{
“href”: “http://api.ifsf.org/ifsf-fdc/v1/sites?zone=Boston&start=16&limit=5”,
“rel”: “previous”
}
]
}
start=id specifies the unique identifier of the expected first element in the result set. If the
element is not found in the result set, the server will respond 410 GONE. This parameter is used
to make sure that elements are not skipped or repeated while paging through the result set.
For instance, if a client should know the sites of the zone “Boston”, but in subsets of 5 elements, should
use the following command:
GET http://api.ifsf.org/ifsf-fdc/v1/sites?zone=Boston&limit=5
This command returns just the first 5 elements. As the initial resource is not specified, the result will
contain the first subset of 5 elements and the link to the next subset.
{
“start”: 1,
“count”: 5,
“totalCount”: 100,
“totalPages”: 20,
“links”: [
{
“href”: “http://api.ifsf.org/ifsf-fdc/v1/sites? zone=Boston&start=6&limit=5”,
“rel”: “next”
}
]
}
The header should contain a link to the previous and next subset, using link headers. If a subset contains
the first element in the complete result set, the header will not contain a “previous” link. The first and
last subsets will not have a “previous” and “next” link, respectively.
GET http://api.ifsf.org/ifsf-fdc/v1/sites?zone=Boston&start=6&limit=5
{
“start”: 6,
“count”: 5,
“totalCount”: 100,
“totalPages”: 20,
“links”: [
{
“href”: “http://api.ifsf.org/ifsf-fdc/v1/sites?zone=Boston&start=11&limit=5”,
“rel”: “next”
},
{
“href”: “http://api.ifsf.org/ifsf-fdc/v1/sites?zone=Boston&limit=5”,
“rel”: “previous”
}
]
In the case site 6 was deleted, a 410 GONE error will be returned and the initial entity should be
requested again.
When a client sends a request, the server response might not be available immediately. The server can
decide to process the request asynchronously. In this case, the server will return HTTP 202 ACCEPT,
create a job resource and return the job resource URL which can be used to query the job state.
If the client queries the job state and the job has been completed, the server will return the API call
response to the client and delete the job resource from the server.
If the API request header includes a callback address and the job is executed asynchronously and the
job has been completed, the server will try to deliver the response using the callback address. If the
callback was successful, the job will be deleted from the server. If the server was unable to reach the
client via callback, the server will not retry the callback. The client can still query the job state using the
job URL.
The server must internally define a job queue size limit and a job queue garbage collection policy for
queue maintenance.
Since the client cannot choose server-side synchronous or asynchronous execution, it must be prepared
for both scenarios in all API calls that support the response 202 Accepted in its specification.
In the following example, a client requests a set of sites that meet a certain condition. The server
calculates the SQL execution plan, decides it will take 30 seconds to calculate the result set, and decides
to process the request asynchronously. The command could be similar to this:
GET http://api.ifsf.org/ifsf-fdc/v1/sites?some-query-parameters
In this case, the response of the server would not be 200 (for GET) or 201 (for PUT or POST). The server
response will be 202 (Accepted) and the body of the response a URL that points to a queue to get the
information when ready:
The client can query the job URL for the job state. If the client queries the job state, while the request
is running, the client will receive HTTP 303 SEE OTHER.
We recommend the server assign expiration TTL to all queued jobs, and expire them regardless the
completion status. This will allow the server to limit how long (maximum) any given task can live in the
queue. Such a strategy is not contrary to the HTTP 202 Accepted declared purpose, and it is allowed for
a resource to never come to existence.
In order to reduce adoption costs, resources will maintain its attributes and attributes naming
convention whenever possible.