diff --git a/artifacts/CAMARA_common.json b/artifacts/CAMARA_common.json new file mode 100644 index 00000000..d7d8b8a5 --- /dev/null +++ b/artifacts/CAMARA_common.json @@ -0,0 +1,359 @@ +{ + "info": { + "description": "Common data and errors for CAMARA APIs", + "version": "0.3.0", + "title": "Common data and errors for CAMARA APIs" + }, + "components": { + "schemas": { + "TimePeriod": { + "properties": { + "startDate": { + "type": "string", + "format": "date-time", + "description": "An instant of time, starting of the TimePeriod" + }, + "endDate": { + "type": "string", + "format": "date-time", + "description": "An instant of time, ending of the TimePeriod. If not included, then the period has no ending date" + } + }, + "required": [ + "startDate" + ] + }, + "ErrorInfo": { + "type": "object", + "required": [ + "message", + "status", + "code" + ], + "properties": { + "message": { + "type": "string", + "description": "A human readable description of what the event represent" + }, + "status": { + "type": "integer", + "description": "HTTP response status code" + }, + "code": { + "type": "string", + "description": "Friendly Code to describe the error" + } + } + } + } + }, + "responses": { + "InvalidArgument": { + "description": "Invalid Argument", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorInfo" + }, + "example": { + "status": 400, + "code": "INVALID_INPUT", + "message": "Schema validation failed at ..." + } + } + } + }, + "Conflict": { + "description": "conflict", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorInfo" + }, + "example": { + "status": 409, + "code": "CONFLICT", + "message": "Schema validation failed at ..." + } + } + } + }, + "FailedPrecondition": { + "description": "Failed precondition", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorInfo" + }, + "example": { + "status": 400, + "code": "FAILED_PRECONDITION", + "message": "Schema validation failed at ..." + } + } + } + }, + "OutOfRange": { + "description": "Out of Range", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorInfo" + }, + "example": { + "status": 400, + "code": "OUT_OF_RANGE", + "message": "Schema validation failed at ..." + } + } + } + }, + "Unauthenticated": { + "description": "Not Authenticated", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorInfo" + }, + "example": { + "status": 401, + "code": "UNAUTHENTICATED", + "message": "Request not authenticated due to missing, invalid, or expired" + } + } + } + }, + "PermissionDenied": { + "description": "Permission denied", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorInfo" + }, + "example": { + "status": 403, + "code": "PERMISSION_DENIED", + "message": "Client does not have sufficient permissions to perform" + } + } + } + }, + "NotFound": { + "description": "Not Found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorInfo" + }, + "example": { + "status": 404, + "code": "NOT_FOUND", + "message": "The specified resource is not found" + } + } + } + }, + "Aborted": { + "description": "Aborted", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorInfo" + }, + "example": { + "status": 409, + "code": "ABORTED", + "message": "Concurrency conflict." + } + } + } + }, + "AlreadyExists": { + "description": "Already Exists", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorInfo" + }, + "example": { + "status": 409, + "code": "ALREADY_EXISTS", + "message": "The resource that a client tried to create already exists." + } + } + } + }, + "TooManyRequests": { + "description": "Already Exists", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorInfo" + }, + "example": { + "status": 429, + "code": "TOO_MANY_REQUESTS", + "message": "Either out of resource quota or reaching rate limiting." + } + } + } + }, + "Internal": { + "description": "Internal Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorInfo" + }, + "example": { + "status": 500, + "code": "INTERNAL", + "message": "Unknown server error.Typically a server bug." + } + } + } + }, + "BadGateway": { + "description": "Bad Gateway", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorInfo" + }, + "example": { + "status": 502, + "code": "BAD_GATEWAY", + "message": "Couldn't reach an upstream internal service." + } + } + } + }, + "Unavailable": { + "description": "Service Unavailable", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorInfo" + }, + "example": { + "status": 504, + "code": "UNAVAILABLE", + "message": "Request timeout exceeded" + } + } + } + }, + "Timeout": { + "description": "Timeout", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorInfo" + }, + "example": { + "status": 503, + "code": "TIMEOUT", + "message": "Request timeout exceeded" + } + } + } + }, + "NotImplemented": { + "description": "Not Implemented", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorInfo" + }, + "example": { + "status": 501, + "code": "NOT_IMPLEMENTED", + "message": "This functionality is not implemented yet" + } + } + } + }, + "AuthenticationRequired": { + "description": "Authentication Required", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorInfo" + }, + "example": { + "status": 401, + "code": "AUTHENTICATION_REQUIRED", + "message": "New authentication is required" + } + } + } + }, + "NotFoundAndOutOfRange": { + "description": "Out Of Range and Not Found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorInfo" + }, + "example": [ + { + "status": 404, + "code": "OUT_OF_RANGE", + "message": "Out Of Range" + }, + { + "status": 404, + "code": "NOT_FOUND", + "message": "Not found" + } + ] + } + } + }, + "MethodNotAllowed": { + "description": "Method not allowed", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorInfo" + }, + "example": { + "status": 405, + "code": "METHOD_NOT_ALLOWED", + "message": "The requested method is not allowed/supported on the target" + } + } + } + }, + "NotAcceptable": { + "description": "Not Acceptable", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorInfo" + }, + "example": { + "status": 406, + "code": "NOT_ACCEPTABLE", + "message": "The server can't produce a response matching the content requested by the client through Accept-* headers" + } + } + } + }, + "UnsupportedMediaType": { + "description": "Unsupported Media Type", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorInfo" + }, + "example": { + "status": 415, + "code": "UNSUPPORTED_MEDIA_TYPE", + "message": "The server refuses to accept the request because the payload format is in an unsupported format." + } + } + } + } + } +} diff --git a/artifacts/Github_templates/.github/ISSUE_TEMPLATE/config.yml b/artifacts/Github_templates/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 00000000..0067a970 --- /dev/null +++ b/artifacts/Github_templates/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,8 @@ +blank_issues_enabled: true +contact_links: + - name: 🗣 Subproject discussions + url: https://github.com/camaraproject/Commonalities/discussions + about: Please ask and answer questions here. + - name: 📖 CAMARA API Design Guidelines + url: https://github.com/camaraproject/Commonalities/blob/main/documentation/API-design-guidelines.md + about: Please refer to the design guidelines. diff --git a/artifacts/Github_templates/.github/ISSUE_TEMPLATE/issue_bug_template.md b/artifacts/Github_templates/.github/ISSUE_TEMPLATE/issue_bug_template.md new file mode 100644 index 00000000..74b42179 --- /dev/null +++ b/artifacts/Github_templates/.github/ISSUE_TEMPLATE/issue_bug_template.md @@ -0,0 +1,33 @@ +--- +name: ‼ Bug 🐛 +about: Describe the bug in Provider Implementation +title: '' +labels: 'implementation:bug' +assignees: '' + +--- + +**Describe the bug** + + +**To Reproduce** + + +**Expected behavior** + + +**Screenshots** + + +**Environment:** + + +**Additional context** + diff --git a/artifacts/Github_templates/.github/ISSUE_TEMPLATE/issue_correction_template.md b/artifacts/Github_templates/.github/ISSUE_TEMPLATE/issue_correction_template.md new file mode 100644 index 00000000..488e70b5 --- /dev/null +++ b/artifacts/Github_templates/.github/ISSUE_TEMPLATE/issue_correction_template.md @@ -0,0 +1,21 @@ +--- +name: ❗ Correction 👣 +about: Suggest the correction of an issue in API specification or a misalignment with API design guidelines +title: '' +labels: 'correction' +assignees: '' + +--- + +**Problem description** + + +**Expected behavior** + + + +**Alternative solution** + + +**Additional context** + diff --git a/artifacts/Github_templates/.github/ISSUE_TEMPLATE/issue_documentation_template.md b/artifacts/Github_templates/.github/ISSUE_TEMPLATE/issue_documentation_template.md new file mode 100644 index 00000000..f7b8de02 --- /dev/null +++ b/artifacts/Github_templates/.github/ISSUE_TEMPLATE/issue_documentation_template.md @@ -0,0 +1,18 @@ +--- +name: ❕ Documentation 📝 +about: Indicate an issue with API documentation or supplementary documents +title: '' +labels: 'documentation' +assignees: '' + +--- + +**Problem description** + + +**Expected action** + + + +**Additional context** + diff --git a/artifacts/Github_templates/.github/ISSUE_TEMPLATE/issue_enhancement_template.md b/artifacts/Github_templates/.github/ISSUE_TEMPLATE/issue_enhancement_template.md new file mode 100644 index 00000000..279ce49a --- /dev/null +++ b/artifacts/Github_templates/.github/ISSUE_TEMPLATE/issue_enhancement_template.md @@ -0,0 +1,20 @@ +--- +name: 💡 Enhancement 🌟 +about: Suggest an idea for a new API feature or pose a question on directions for API evolution +title: '' +labels: 'enhancement' +assignees: '' + +--- + +**Problem description** + + +**Possible evolution** + + +**Alternative solution** + + +**Additional context** + diff --git a/artifacts/Github_templates/.github/ISSUE_TEMPLATE/issue_pm_template.md b/artifacts/Github_templates/.github/ISSUE_TEMPLATE/issue_pm_template.md new file mode 100644 index 00000000..210a2f06 --- /dev/null +++ b/artifacts/Github_templates/.github/ISSUE_TEMPLATE/issue_pm_template.md @@ -0,0 +1,18 @@ +--- +name: ☁ Subproject management 🎂 +about: Indicate an issue with subproject repository or release management +title: '' +labels: 'subproject management' +assignees: '' + +--- + +**Problem description** + + +**Expected action** + + + +**Additional context** + diff --git a/artifacts/Github_templates/.github/ISSUE_TEMPLATE/issue_tests_template.md b/artifacts/Github_templates/.github/ISSUE_TEMPLATE/issue_tests_template.md new file mode 100644 index 00000000..170874a8 --- /dev/null +++ b/artifacts/Github_templates/.github/ISSUE_TEMPLATE/issue_tests_template.md @@ -0,0 +1,18 @@ +--- +name: ⁉ Tests 🔎 +about: Indicate an issue with API tests +title: '' +labels: 'tests' +assignees: '' + +--- + +**Problem description** + + +**Expected action** + + + +**Additional context** + diff --git a/artifacts/Github_templates/.github/pull_request_template.md b/artifacts/Github_templates/.github/pull_request_template.md new file mode 100644 index 00000000..cdebc5af --- /dev/null +++ b/artifacts/Github_templates/.github/pull_request_template.md @@ -0,0 +1,46 @@ + +#### What type of PR is this? + +Add one of the following kinds: +* bug +* correction +* enhancement/feature +* cleanup +* documentation +* subproject management +* tests + + +#### What this PR does / why we need it: + + + + +#### Which issue(s) this PR fixes: + + + +Fixes # + +#### Special notes for reviewers: + + + +#### Changelog input + +``` + release-note + +``` + +#### Additional documentation + +This section can be blank. + + + +``` +docs + +``` diff --git a/code/API_definitions/README.MD b/code/API_definitions/README.MD deleted file mode 100644 index 04313f15..00000000 --- a/code/API_definitions/README.MD +++ /dev/null @@ -1 +0,0 @@ -Here you can add your definitions and delete this README.MD file diff --git a/documentation/API-DocumentationTemplate.md b/documentation/API-DocumentationTemplate.md new file mode 100644 index 00000000..e36601ec --- /dev/null +++ b/documentation/API-DocumentationTemplate.md @@ -0,0 +1,17 @@ +# API documentation template + +| Section | Sub-section | Description | Mandatory | +|----|---|---|-| +| Overview | Introduction | This section gives an overview of the API. It explains the use of the API and gives an insight on its benefits. A few lines on some standard use cases can help better explain the API | Yes | +|| Quick Start|It explains how developers can get started with this API. A good example is the Stripe-API documentation: https://stripe.com/docs/api || +|Authentication and/or Authorization | |It explains how developers/consumers can access the API. Failure to document the authN-authZ schema in a simple and precise way can deter first time API users . |Yes| +|Documentation|Details|This is an optional section/placeholder. It could include some detailed descriptions or diagrams explaining things in further details and the subsection heading could be changed accordingly.| | +| |Endpoint definitions | What does each endpoint do is a critical part of the API documentation. It explains the consumer/developer your internal system. The documentation should explain what an endpoint is for and how it relates to other endpoints. It should also document:
- HTTP verb methods supported.
- Parameters along with description
- HTTP codes expected + HTTP response bodies
- HTTP Request and Response headers
- Pagination details if applicable
If there are any constraints for an endpoint, it should be documented in this section.
It should be made clear if certain endpoints are restricted to only certain roles/users. | Yes | +| |Errors|Error types along with error codes summary table can offer a good reference for the developers working with the API | Yes | +| |Policies|How the developer can discover the usage policy for each endpoint - e.g. limits on requests per second, any regional limitations on what can be returrned in the resource representation, etc. These policies will be operator-specific but the mechanism to discover them should be consistent | No | +| |Code snippets| Copy-paste sample code snippets help developers to get started right away. It helps provide a rich developer experience. This can include sample request examples, and the ability to execute samples directly from the documentation Web page (as per Open API). | No | +| |FAQs| List of frequently asked questions by the early developers/users of the API |No | +| |Terms|Terms of Service |No (N/A for Camara| +| |Release Notes|Listof all changes included in the release |Yes| +| |Pricing |Details about pricing |No (N/A for Camara)| +|API Spec || Complete API Spec in YAML format | Yes | diff --git a/documentation/API-Readiness-Checklist.md b/documentation/API-Readiness-Checklist.md new file mode 100644 index 00000000..a07b1261 --- /dev/null +++ b/documentation/API-Readiness-Checklist.md @@ -0,0 +1,11 @@ +# API Readiness minimum criteria checklist +| No | Deliverables/Criteria | Mandatory | Reference template | +|----|-------------- |-----------|-------------------- | +| 1 |API Spec | Y | OAS3 (https://spec.openapis.org/oas/v3.0.3)| +| 2 |API Implementation | N | | +| 3 |API Documentation | Y |https://github.com/camaraproject/Commonalities/blob/main/documentation/API-DocumentationTemplate.md | +|4 |User Stories | Y | https://github.com/camaraproject/Commonalities/blob/main/documentation/Userstory-template.md | +| 5 |API test cases and documentation | Y | TBD | +| 6 |Tested by atleast 2 operators | Y | | +| 7 |Security review | Y | Spec contributions should include a security scheme section that complies with the AuthN&AuthZ techniques agreed in Commonalities. | + diff --git a/documentation/API-design-guidelines.md b/documentation/API-design-guidelines.md new file mode 100644 index 00000000..ee454c41 --- /dev/null +++ b/documentation/API-design-guidelines.md @@ -0,0 +1,1396 @@ +# API design guidelines + +This document captures guidelines for the API design in CAMARA project. These guidelines are applicable to every API to be worked out under the CAMARA initiative. + +## Table of Contents + +- [API design guidelines](#api-design-guidelines) + - [Table of Contents](#table-of-contents) + - [Common Vocabulary and Acronyms](#common-vocabulary-and-acronyms) + - [1. Introduction](#1-introduction) + - [2. APIfication Principles](#2-apification-principles) + - [2.1 Domain Driven Design](#21-domain-driven-design) + - [2.2 API First](#22-api-first) + - [2.3 Interface standardization. Standardization fora.](#23-interface-standardization-standardization-fora) + - [2.4 Information Representation Standard](#24-information-representation-standard) + - [2.5 Reduce telco-specific terminology in API definitions](#25-reduce-telco-specific-terminology-in-api-definitions) + - [3. API Definition](#3-api-definition) + - [3.1 API REST](#31-api-rest) + - [3.2 HTTP Response Codes](#32-http-response-codes) + - [3.3 Query Parameters Use](#33-query-parameters-use) + - [3.4 Path Parameters Use](#34-path-parameters-use) + - [3.5 HTTP Headers Definition](#35-http-headers-definition) + - [3.6 MIME Types](#36-mime-types) + - [4. API Resource Definition](#4-api-resource-definition) + - [4.1 URL Definition](#41-url-definition) + - [4.2 Input/Output Resource Definition](#42-inputoutput-resource-definition) + - [5. Versioning](#5-versioning) + - [5.1 Versioning Strategy](#51-versioning-strategy) + - [5.2 Backwards and Forward Compatibility](#52-backwards-and-forward-compatibility) + - [6. Error Responses](#6-error-responses) + - [7. Common Data Types](#7-common-data-types) + - [8. Pagination, Sorting and Filtering](#8-pagination-sorting-and-filtering) + - [8.1 Pagination](#81-pagination) + - [8.2 Sorting](#82-sorting) + - [8.3 Filtering](#83-filtering) + - [9. Architecture Headers](#9-architecture-headers) + - [10. Security](#10-security) + - [10.1 API REST Security](#101-api-rest-security) + - [10.2 Security Implementation](#102-security-implementation) + - [11. Definition in OpenAPI](#11-definition-in-openapi) + - [11.1 General Information](#111-general-information) + - [11.2 Published Routes](#112-published-routes) + - [11.3 Request Parameters](#113-request-parameters) + - [11.4 Response Structure](#114-response-structure) + - [11.5 Data Definitions](#115-data-definitions) + - [11.6 OAuth Definition](#116-oauth-definition) + - [12. Subscription, Notification \& Event](#12-subscription-notification--event) + - [12.1 Subscription](#121-subscription) + - [12.2 Event notification](#122-event-notification) + + +## Common Vocabulary and Acronyms + +| **Term** | Description | +| --- | --- | +|**API** | Application Programming Interface. It is a rule & specification group (code) that applications follow to comunicate between them, used as interface among programs developed with different technologies.| +|**Body**| HTTP Message body (If exists) is used to carry the entity data associated with the request or response.| +|**Camel Case**| It is a kind of define the fields’ compound name or phrases without whitespaces among words. It uses a capital letter at the beginning of each word. There are two different uses:
  • Upper Camel Case: When the first letter of each word is capital.
  • Lower Camel Case: Same that Upper one, but with the first word in lowercase.
  • | +|**Header**| HTTP Headers allow client and server send additional information joined to the request or response. A request header is divided by name (No case sensitive) followed by colon and the header value (without line breaks). White spaces on the left hand from the value are ignored.| +|**HTTP**| Hypertext Transfer Protocol (HTTP) is communication protocol that allows the information transfer using files (XHTML, HTML…) in World Wide Web.| +|**JSON**| JavaScript Object Notation| +|**JWT**| JSON Web Token (JWT) is an open standard based on JSON proposed by IETF (RFC 7519) for access token creations allowing the identity and purposes spread. | +|**Kebab-case**| Practice in the words denomination where the hyphen is used to separate words. | +|**OAuth**| Open Authorization is an open standard that allows simple Authorization flows to be used in web sites or applications.| +|**REST**| Representational State Transfer.| +|**TLS**| Transport Layer Security or TLS is a cryptographic protocol that provides secured network communications. | +|**URI**| Uniform Resource Identifier. | +|**Snake_case**|Practice in the words denomination where the underscore is used to separate words. | + + +## 1. Introduction +The purpose of this document is to technically describe aspects related to the proper design of Application Programming Interfaces (hereinafter API), so that it serves as a recommended reference for the development of APIs in telco operators and related projects. + +Based on principles of standardization, normalization and good practices, this document explains the guidelines for the design and definition of an API, elaborating the following points: + +- How to make a proper API definition. +- What are the main aspects to cover. +- What are the best practices for designing an API and managing it properly. + +This document is addressed to all the roles and people that may participate in a Programmable Interface (API) design and assumes that they have basic knowledge of what an API is. + + +## 2. APIfication Principles + +APIs are critical components of digitization that enable us to expose the functions and capabilities existing in our systems and network in a secure and standardized way (service channels, between systems/platforms and third parties/partners) without needing to redesign or re-create them (enhancing reuse) with the consequent saving of time and investment. + +The APIfication program is based on the following key principles: i) Domain Driven Design; ii) API First; and iii) Standardization. + +### 2.1 Domain Driven Design +The main idea of the Domain Driven Design (DDD) approach is "to develop software for a complex domain, we need to build a ubiquitous language that embeds the domain's terminology in the software systems we build" (Fowler, 2020). + +This approach to software development focuses efforts on defining, for each defined domain, a model that includes a broad understanding of the processes and rules of that domain. + +DDD approach is particularly suitable for complex domains, where a lot of messy logic needs to be organized. +The DDD principles are based on: + +- Placing the organization's business models and rules in the core of the application. +- Obtain a better perspective at the level of collaboration between domain experts and developers, to conceive software with very clear objectives. + +As an initial reference to define the different domains and subdomains, we rely on the TM Forum SID model, illustrated in the figure below. + +![TMF SID](./images/guidelines-fig-1.png) + +This set of domains and subdomains is not fixed or static and can evolve over time, depending on the needs for the development and conceptualization of new business or technological elements. + +The following figure shows a representation of the concepts handled by the Domain Driven Design approach. The entities located at the bottom are those necessary to analyse the domain, while those at the top of the graph are related to the more technical part of software architecture. Therefore, Domain Driven Design is an "approach to the design of software solutions that ranges from the most holistic definition to the implementation of the objects in the code". +![Domain Driven Design approach ](./images/guidelines-fig-2.png) + +### 2.2 API First + +API First strategy consists of considering APIs and everything related to them (definition, versioning, development, promotion...) as a product. + +This design strategy considers the API as the main interface of the application and initially begins with its design and documentation, to later develop the backend part, instead of setting up the entire backend first and then adapting the API to everything built. + +In this way, the technological infrastructure depends directly on the design of the services instead of being a response to their implementation. + +Among the main benefits of an "API First" development strategy we can highlight: + +- Development teams can work in parallel. +- Reduces the cost of application development. +- Increases speed to market. +- Ensures good developer experiences. + + + +### 2.3 Interface standardization. Standardization fora. + +In order to ensure the reusability of the different integrations between elements and systems is essential the agreement of the industry (network element providers, system providers, customer service providers, ...) defining a series of interfaces that ensure specific functionality and responses. + +There are different organizations, standardization forums and collaboration projects that define specific interfaces for certain domains, which are then implemented by different industry agents: integrators, software manufacturers, etc... Some of these organizations, specialized in network domains, include 3GPP, ETSI, IETF and Broadband Forum, among others. + +At the systems level, the reference organization is the Telemanagement Forum (TM Forum). TM Forum is a global association that drives collaboration and collective problem solving to maximize the business success of telecommunications companies and their provider ecosystem. Its purpose is to help this ecosystem to transform and prosper in the digital age. + +**TM Forum Frameworx** is a set of best practices and standards for evaluating and optimizing process performance, using a service approach to operations. The tools available in Frameworx help to improve end-to-end service management in complex, multi-stakeholder environments. It has been widely adopted by the telecommunications industry, providing a common language of processes, functional capabilities, and information. + +The TM Forum Frameworx is composed of: + +- Business Process Framework, also known to as enhanced Telecom Operations Map (`eTOM`): it is a reference framework for defining the business processes of telecommunications operators. +- Application Framework Fundamentals (`TAM`): it groups functionalities into recognizable applications to automate processes that will help us to plan and optimize an application portfolio. +- The Information Framework, also known to as Shared Information/Data Model (`SID`): it unifies reference data model that provides a single set of terms for business objects in telecommunications. The goal is to enable people from different departments, companies, or geographic locations to use the same terms to describe the same real-world objects, practices, and relationships. + +Over the last years, TMForum is performing a complete transformation of its architecture, moving from Frameworx, whose paradigm is based on applications, to the Open Digital Architecture (`ODA`), based on modular components. + +TM Forum further defines a set of reference APIs (TMF Open APIs) between the different architecture components. + + +### 2.4 Information Representation Standard + +As a messaging standard, the use of JSON is proposed by default, since it is a light data exchange format and is commonly adopted by current web technologies, although this does not imply that other types of data cannot be used depending on functional and technical requirements. + +JSON is made up with two structures: + +- A collection of key/value pairs. In various languages this is known as an object, record, structure, dictionary, hash table, key list, or an associative array. +- An ordered list of values. In most languages, this is implemented as arrays, vectors, lists, or sequences. +Data exchange format that is independent of the programming language is based on universal structures supported virtually in all programming languages. + +In JSON, the following structures are represented. + +An **object** is an unordered set of key/value pairs. An object starts with a "`{`" opening brace and ends with a "`}`" closing brace. Each name is followed by a “`:`” colon and key/value pairs are separated by a “`,`” comma. +

    +drawing +

    + +An **array** is a collection of values. An array starts with “`[`“ left bracket and ends with “`]`” right bracket. Values are separated by "`,`" comma. +

    +drawing +

    + +A **value** can be a string with double quotes, or a number, or true or false or null, or an object or an array. These structures can be nested. +

    +drawing +

    + +A **character string** is a collection of zero or more Unicode characters, enclosed in double quotes, using backslash escaping. A character is represented by a character string of a single character. A character string is similar to a C or Java character string. +

    + +

    + + +A **number** is similar to a C or Java number, except that octal and hexadecimal formats are not used. +

    + +

    + +**White spaces** can be inserted between any pair of symbols. +

    +drawing +

    + +Except for minor enconding details, the above-mentioned structures provide a full description of JSON language. + +## 2.5 Reduce telco-specific terminology in API definitions +CAMARA aims to produce 'intent-based' APIs, which have two key benefits: +- for the developer: it does not assume familiarity with the network that will fulfil the API. +- for the operator: it avoids tight-coupling, meaning the API can be fulfilled by various networks (mobile, fixed, satellite etc.) and network versions (4/5/6G etc.) + +To realise these benefits it is important to reduce the use of telco-specific terminolgy/acronyms in developer-facing APIs. + +CAMARA API designers should: +- Consider and account for how the API can be fulfilled on a range of network types +- Avoid terms/types specific to a given telco domain. For example the acronym 'UE': in 3GPP terminology this refers to 'User Equipment', but 'UE' means 'User Experience' for most Web developers: 'Terminal' would be a more appropriate, and unambiguous, term. If use of a telco-specific term is unavoidable, either: +- - allow a choice, so the developer can utilise other types. E.g. `MSISDN` should not be the _only_ way to identify an end user. +- - use abstractions, which can evolve: e.g. an `endUserIdentifier` enumeration can support mulitple identifiers. +- - explain the telco-specific term in the documentation, and any constraints it brings. + + +## 3. API Definition + +API definition aims to capture 100% of the functional, syntax and semantic documentation of a contract. It is a critical element for the business strategy and will tag the product offered success. + +Outstanding aspects in the API definition are: + +- API must be defined from a product view focused to API consumers. It means, it should be prepared a top-down definition of all APIs. +- Product should be focused on the usability. +- API contract must be correctly documented, and it will be published in a shared catalog. +- API exposure definition will be based on “resources could be used by different services and product consumers”. That means, API definition should be a 360-degree product view. + +API definition must consider the next assertions: + +- API resources definition contains the URI and enterprise resources. +- REST specification compliance aims make the API fully interoperable. +- API resource security. +- Product consumption experience. +- API measurement over how many, who and when it is used. +- API must be versioned, and version must figure in all operations URL. It allows a better last develops management and surveillance, it avoids out of date URLs request and it makes available coexistence of more than one version productive in the same environment. +- Expose the required fields by the API consumers only. Sometimes, all the response body is not necessary for consumers. Allows more security, less the network traffic and agile the API usability. +- One of the API Quality requirements will be the evolution and management scalability, lined with versioning and backward compatibility considerations detailed in this document. +- At API definition time is necessary include audit parameters to allow make surveillance and next maintenances. +- English use must be applied in the OpenAPI definition. + +### 3.1 API REST + +Representational state transfer (REST) is a software architectural style that was created to guide the design and development of the architecture for the World Wide Web. REST defines a set of constraints for how the architecture of an Internet-scale distributed hypermedia system, such as the Web, should behave. + +The formal REST constraints are as follows: + +- **Client–server architecture**. The client-server design pattern enforces the principle of separation of concerns: separating the user interface concerns from the data storage concerns. Portability of the user interface is thus improved. In the case of the Web, a plethora of web browsers have been developed for most platforms without the need for knowledge of any server implementations. Separation also simplifies the server components, improving scalability, but more importantly it allows components to evolve independently (anarchic scalability), which is necessary in an Internet-scale environment that involves multiple organisational domains. +- **Statelessness**. In computing, a stateless protocol is a communications protocol in which no session information is retained by the receiver, usually a server. Relevant session data is sent to the receiver by the client in such a way that every packet of information transferred can be understood in isolation, without context information from previous packets in the session. This property of stateless protocols makes them ideal in high volume applications, increasing performance by removing server load caused by retention of session information. +- **Cacheability**: As on the World Wide Web, clients and intermediaries can cache responses. Responses must, implicitly or explicitly, define themselves as either cacheable or non-cacheable to prevent clients from providing stale or inappropriate data in response to further requests. Well-managed caching partially or eliminates some client–server interactions, further improving scalability and performance. +- **Layered system**: A client cannot ordinarily tell whether it is connected directly to the end server or to an intermediary along the way. If a proxy or load balancer is placed between the client and server, it won't affect their communications, and there won't be a need to update the client or server code. +- **Uniform interface**: The uniform interface constraint is fundamental to the design of any RESTful system. It simplifies and decouples the architecture, which enables each part to evolve independently. The four constraints for this uniform interface are: + - Resource identification in requests. Individual resources are identified in requests, for example using URIs in RESTful Web services. The resources themselves are conceptually separate from the representations that are returned to the client. For example, the server could send data from its database as HTML, XML or as JSON—none of which are the server's internal representation. + - Resource manipulation through representations. When a client holds a representation of a resource, including any metadata attached, it has enough information to modify or delete the resource's state. + - Self-descriptive messages. Each message includes enough information to describe how to process the message. For example, which parser to invoke can be specified by a media type. + - Hypermedia as the engine of application state (HATEOAS). Having accessed an initial URI for the REST application) analogous to a human Web user accessing the home page of a website) a REST client should then be able to use server-provided links dynamically to discover all the available resources it needs. As access proceeds, the server responds with text that includes hyperlinks to other resources that are currently available. There is no need for the client to be hard-coded with information regarding the structure or dynamics of the application. + + HTTP verbs + +HTTP standard should be followed to the verbs usability, resulting an API definition oriented to the RESTful design. Any HTTP correct verb usability are allowed. + +Principal methods (Verbs) available to use are next ones: + +| **HTTP Verb** | **CRUD operation** | **Description** | +| ---- | ----| ----| +GET | Read | Retrieve the actual resource status | +POST | Create | Creates a new resource in the collection. Returns the resource URL when the creation ends.| +PUT | Update | Replaces a specific resource. Returns the resource URL when the replace ends. | +DELETE | Delete | Delete a specific resource. | +PATCH | Update | Updates a specific resource, applying all changes at the same time. If resource does not exist, it will be created. Returns the resource URL when the update ends. If any error occurs during the update, all of them will be cancelled. | +OPTIONS | Read | Returns a 200 OK with an allowed methods list in the specific resource destined to the header allowed joined to an HTML document about the resource + an API Doc link. | +HEAD | Read | Returns the resource actual status without message body. | + +In this document will be defined the principal verbs to use in the API definition. + +- `POST`: it is used to send date to the server. +- `GET`: it allows performing all the read and retrieve operations. GET operation should be based on data retrieving, that’s why the retrieve operation must be realized directly from the URI including some identifiers and query params. +- `PUT`: it allows update entity data, deleting one or more fields from this entity body if there are not informed. New information to update must be informed by JSON language sent in the body request. If operation requires extra information, Query params could be used. PUT case, if registry does not exist in server data storage, it will be created, that means this operation could be used to create new resources. +- `DELETE`: it allows deleting full entities from server. From consumer perspective, it is not a reversible action. (Rollback action is not available). +- `PATCH`: it allows updating partial fields of a resource. + +
    + +#### **POST or GET for transferring sensitive or complex data** + +Using the GET operation to pass senstive data potentially embeds this information in the URL if contained in query or path parameters. For example, this information can remain in browser history, could be visible to anyone who can read the URL, or could be logged by elements along the route such as gateways and load balancers. This increases the risk that the sensitive data may be acquired by unauthorised 3rd parties. Using HTTPS does not solve this vulnerability, as the TLS termination points are not necessarily the same as the API endpoints themselves. + +The classification of data tagged as sensitive should be assessed for each API project, but might include the following examples: +- phone number (MSISDN) must be cautiously handled as it is not solely about the number itself, but also knowing something about what transactions are being processed for that customer +- localisation information (such as latitude & longitude) associated with a device identifier as it allows the device, and hence customer, location to be known +- physical device identifiers, such as IP addresses, MAC addresses or IMEI + +In such cases, it is recommended to use one of the following methods to transfer the sensitive data: +- When using `GET`, transfer the data using headers, which are not routinely logged or cached +- Use `POST` instead of `GET`, with the sensitive data being embedded in the request body which, again, is not routinely logged or cached + +When the `POST` method is used, the resource in the path *must* be a verb (e.g. `retrieve-location` and not `location`) to differentiate from an actual resource creation. + +It is also fine to use POST instead of GET: +- to bypass technical limitations, such as URL character limits (if longer than 4k characters) or passing complex objects in the request +- for operations where the response should not be kept cached, such as anti-fraud verifications or data that can change asynchronously (such as status information) + +### 3.2 HTTP Response Codes + +HTTP status response codes indicate if a request has been completed successfully. Response codes are group by five classes. + +1. Inform responses (1XX) +2. Success responses (2XX) +3. Redirections (3XX) +4. Client Errors (4XX) +5. Server Errors (5XX) + +Status codes are defined in the [RFC 2616](https://tools.ietf.org/html/rfc2616#section-10) 10th section. You can get the updated specifications from [RFC 7231](https://tools.ietf.org/html/rfc7231#section-6.5.1). + +Common errors are captured in the table below. + +| **Error code** | **Description** | +| ---| ---| +| 200 | 200 (OK) status code indicates that the request result successfully
    `GET`-> 200 HTTP Code by default.
    `POST`/`PUT`/`PATCH` -> Resource update actions, data is returned in a body from server side.
    `DELETE` -> Resource delete action, data is returned in a body from server side.
    | +| 201 | 201 (Created) HTTP code indicates that the request has created one or more resource successfully.
    `POST`/`PUT` -> When a resource is created successfully.| +| 202 | 202 (Accepted) code indicated that the request has been accepted to be processed, but it has not ended.
    Usually, when a `DELETE` is requested but the server cannot make the action immediately. It should applies to async processes. | +| 203 | 203 (Unathourized information) code indicated that the request has been successfully, but the attached payload was modified from the 200 (OK) response from the origin server using a transformation proxy.
    It is used when data sent in the request could be modified as a third data subset.| +| 204 | 204 (No Content) indicated that the server has ended successfully the request and there are nothing to return in the body response.
    `POST` -> When used to modify a resource and output is not returned.
    `PUT`/`PATCH` -> When used to modify a resource and output is not returned.
    `DELETE` -> Resource delete action and output is not returned.
    _NOTE: This list of levels MAY be extended with new values. The OpenID Provider (Auth Server) and the APIs used by the Relying Parties (client Applications) MUST be ready to support new values in the future._| +| 206 | 206 (Partial Content) The server has fulfilled the partial GET request for the resource. +| 400 | 400 (Bad Request) status code indicates that the server cannot or will not process the request due to something perceived as a client error (for example, malformed request syntax, invalid request message structure, or incorrect routing).
    This code must be documented in all the operations in which it is necessary to receive data in the request.| +| 401 | 401 (Unauthorized) status code indicates that the request has not been applied because it lacks valid authentication credentials for the target resource.
    This code has to be documented in all API operations that require subscription by a client.| +| 403 | 403 (Forbidden) status code indicates that the server understood the request, but is refusing to authorize it. A server that wants to make public why the request was prohibited can describe that reason in the response payload (if applicable).
    This code is usually documented in the operations. It will be returned when the OAuth token access does not have the required scope or when the user fails operational security.| +| 404 | 404 (Not Found) status code indicates that the origin server either did not find a current representation for the target resource or is unwilling to reveal that it exists.
    This code will occur on `GET` operations when the resource is not available, so it is necessary to document this return in such situations.| +| 405 | 405 (Method Not Allowed) status code indicates that the origin server knows about the method received in the request line, but the target resource does not support it.
    This code is documented at the API portal level, it should not be documented at the API level.| +| 406 | 406 (Not Acceptable) status code indicates that the target resource does not have a current representation that would be acceptable to the user, based on the proactive negotiation header fields received in the request, and the server is unwilling to provide a predetermined representation. It must be reported when there is no response by default, and header fields are reported to carry out the content negotiation (Accept, Accept-Charset, Accept-Encoding, Accept-Language). | +| 408 | Status code 408 (Request Timeout) indicates that the server did not receive the complete request message within the expected time.
    This code is documented at the API portal level, it should not be documented at the API level.| +| 409 | The 409 (Conflict) status code indicates when a request conflicts with the current state of the server. | +| 500 | Status code 500 (Internal Server Error) indicates that the server encountered an unexpected condition that prevented it from fulfilling the request.
    This code must always be documented. It should be used as a general system error.| +| 501 | Status code 501 (Not Implemented) indicates that the requested method is not supported by the server and cannot be handled. The only methods that servers require support (and therefore should not return this code) are `GET` and HEAD. | +| 502 | Status code 502 (Bad Gateway) indicates that the server, while working as a gateway to get a response needed to handle the request, got an invalid response. | +| 503 | Status code 503 (Service Unavailable) status code indicates that the server is currently unable to handle the request due to a temporary overload or scheduled maintenance, which will likely be alleviated after some delay. | +| 504 | Status code 504 (Gateway Timeout) indicates that the server is acting as a gateway and cannot get a response in time. | + +### 3.3 Query Parameters Use + +API query parameters can be defined as key-value pairs that appear after the question mark in the URL. Basically, they are URL extensions used to help determine the specific content or action based on the data being delivered. Query parameters are added at the end of the URL, using a "`?`". The question mark is used to separate the path and the query parameters. + +

    +drawing +

    + +If you want to add multiple query parameters, an "`&`" is placed between them to form a query string. You can present lot of objects types with different lengths, such as arrays, strings, and numbers. + +### 3.4 Path Parameters Use + +A path param is a unique identifier for the resource. For example: + +- ```/users/{userId}``` + +Multiple path params can be entered if there is a logical path of mutually dependent resources. +- ```/users/{userId}/documents/{documentId}``` + + Good Practices + + +1. Path params cannot be concatenated. A path param must be preceded by the resource represented. If we did this, the URL would be incomprehensible: + - ```/users/{userId}/{documentId}``` + - ```/users/13225365/647658``` +

    +2. The attribute must be identifying itself, it is not enough with "`{id}`" + - ```/users/{id}``` +

    + + Reason is that if this resource is "extended" in the future and includes other identifiers, we would not know which of the entities the "`{id}`" parameter refers to. For example: + - Incorrect: ```/users/{id}/documents/{documentId}``` + - Correct: ```/users/{userId}/documents/{documentId}``` +

    +3. It is recommended that the identifier have a similar morphology on all endpoints. For example, “`xxxxId`”, where xxx is the name of the entity it references: + - ```/users/{userId}``` + - ```/accounts/{accountId}``` + - ```/vehicles/{vehicleId}``` + - ```/users/{userId}/vehicles/{vehicleId}``` +

    +4. Care must be taken not to create ambiguities in the URIs when defining paths. For example, if the "user" entity can be identified by two unique identifiers and we will create two URIs. + - ```/users/{userId}``` + - ```/users/{nif}``` +

    +5. Identifiers must be, as far as possible, of a hash type or similar so that we avoid enumeration or brute force attacks for their deduction. + +Upon API invocation, one of the options would be chosen and we would not be able to distinguish which one was chosen. + +### 3.5 HTTP Headers Definition +Request header parameters are a great addition to the design of our API functionality. The purpose of this document is not to describe all the possibilities offered by the HTTP protocol, but to try to take the use of HTTP headers into account during the definition and design of APIs, in order to improve their characteristics. + +The main HTTP headers are described below: + +- `Accept`: this header can be used to specify certain types of data that are acceptable for the response. `Accept` headers can be used to indicate that the request is specifically limited to a small set of desired types, as in the case of a request for an image. +- `Accept-Encoding`: similar to the `Accept` header, but restricting the content encodings that are acceptable in the response. +- `Accept-Language`: the consumer defines the list of languages in order of preference. The server answer with the `Content-Language` field in the header with the response language. +- `Authorization`: it allows sending the authorization token for API access, initially OAuth and JWT. +- `Content-Type`: it indicates the type of message sent to the recipient or, in the case of the HEAD method, the type of message that would have been sent if the request had been a GET. The MIME type of the response, or the content uploaded via POST/PUT in case it is a request. +- `Content-Length`: it indicates the message size, in octets, sent to the recipient or, in the case of the HEAD method, the message size that would have been sent if the request had been a GET. The size of the response in octets (8 bits) +- `Content-Encoding`: it is used as a message type modifier. The type of encoding used in the response is indicated. +- `Host`: specifies the host and port number of the server to which the request is being sent. + + Optional recommendended security headers by OWASP + +- `HTTP Strict Transport Security`: a web security policy mechanism which helps to protect websites against protocol downgrade attacks and cookie hijacking. t allows web servers to declare that web browsers (or other complying user agents) should only interact with it using secure HTTPS connections, and never via the insecure HTTP protocol. +- `X-Frame-Options`: a response header (also named XFO) which improves the protection of web applications against clickjacking. It instructs the browser whether the content can be displayed within frames. +- `X-Content-Type-Options`: setting this header will prevent the browser from interpreting files as a different MIME type to what is specified in the Content-Type HTTP header (e.g. treating text/plain as text/css). +- `Content-Security-Policy`: it requires careful tuning and precise definition of the policy. If enabled, CSP has significant impact on the way browsers render pages (e.g., inline JavaScript is disabled by default and must be explicitly allowed in the policy). CSP prevents a wide range of attacks, including cross-site scripting and other cross-site injections. +- `X-Permitted-Cross-Domain-Policies`: a cross-domain policy file is an XML document that grants a web client, such as Adobe Flash Player or Adobe Acrobat (though not necessarily limited to these), permission to handle data across domains. When clients request content hosted on a particular source domain and that content makes requests directed towards a domain other than its own, the remote domain needs to host a cross-domain policy file that grants access to the source domain, allowing the client to continue the transaction. +- `Referrer-Policy`: it governs which referrer information (sent in the Referer header) should be included with requests made. +- `Clear-Site-Data`: it clears browsing data (e.g., cookies, storage, cache) associated with the requesting website. It allows web developers to have more control over the data stored locally by a browser for their origins. +- `Cross-Origin-Embedder-Policy`: it prevents a document from loading any cross-origin resources that don’t explicitly grant the document permission +- `Cross-Origin-Opener-Policy`: this response header (also referred to as COOP) allows you to ensure a top-level document does not share a browsing context group with cross-origin documents. COOP will process-isolate your document and potential attackers can’t access to your global object if they were opening it in a popup, preventing a set of cross-origin attacks dubbed XS-Leaks +- `Cross-Origin-Resource-Policy`: this response header (also referred to as CORP) allows to define a policy that lets web sites and applications opt in to protection against certain requests from other origins (such as those issued with elements like "`