Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADR] API contract conventions #46

Open
StevenMalaihollo opened this issue May 3, 2022 · 3 comments
Open

[ADR] API contract conventions #46

StevenMalaihollo opened this issue May 3, 2022 · 3 comments
Labels

Comments

@StevenMalaihollo
Copy link
Contributor

StevenMalaihollo commented May 3, 2022

Context

For the Core APIs we are setting a standard for how OpenAPIs should look like within BCC.

Proposition

Enums

The values used within Enums will be PascalCase. This is to stay backwards compatible with previously connected systems.

Timestamps

Dates where time is irrelevant (such as birth dates, deceased dates, contract dates etc.) should look like: 2022-05-03. These dates should not have a timezone or time component.
Regular timestamps should conform to the iso 8601. This means that a timezone and time component is stored.

Null values

Should be looked at on a case by case basis.

Querying

For querying in our APIs we want to build according to the Odata query syntax. This syntax should only be implemented according to need. For now we are interesting in using:

  • $filter
  • $top
  • $skip
  • $select
  • $expand
  • $orderby
  • $search
@github-actions
Copy link

github-actions bot commented May 3, 2022

Remember that ADRs are publicly available hence do not include any confidential information in the issue description!
To read more about ADR please refer to documentation.

@StevenMalaihollo
Copy link
Contributor Author

StevenMalaihollo commented May 10, 2022

Querying revisit

Odata query implementation does not fit well with our APIs. Other standards don't seem to help us or the consumer either. So we will build a strong set of custom querying features based on DirectUs fields:

  • fields
  • filter according to JSON
  • search
  • sort
  • limit
  • offset
  • page

Responses

Some standards make use of wrapper types like meta, data and more. In general we follow the way DirectUs structures responses.

type Wrapped = {
    data?: object | object[]; // Can be omitted if there is an error
    meta?: Meta; // Can be omitted for single item requests
    error?: ErrorResponse; // Can be omitted if there is no error or 'errors' is defined
    errors?: ErrorResponse[]; // Can be omitted if there is no error or 'error' is defined
};

interface Meta {
    total: number;
    skipped: number;
    limit: number;
    // Other optional properties
}

interface ErrorResponse {
    message: string;
    code?: string;
    // Other optional properties
}

// examples:
const errorResponse: Wrapped = {
    error: {
        code: 'invalid-query',
        message: "Invalid query: 'foo' is not a valid query parameter",
    },
};

const singleItemResponse: Wrapped = {
    data: {
        id: '123',
        name: 'John Doe',
    },
};

const multipleItemsResponse: Wrapped = {
    data: [
        {
            id: '123',
            name: 'John Doe',
        },
        {
            id: '456',
            name: 'Jane Doe',
        },
    ],
    meta: {
        total: 7,
        skipped: 0,
        limit: 2,
    },
};

@rvanoord
Copy link
Member

rvanoord commented May 30, 2022

I like the proposal @JakubC-projects. We could consider using errorCode instead of just code which is a bit ambiguous (since HTTP status code is also relevant in this context).

The type Wrapped could perhaps be called ApiResponse or ResponseMessage or similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants