Convert Figma logo to code with AI

WhiteHouse logoapi-standards

No description available

3,081
902
3,081
34

Top Related Projects

Microsoft REST API Guidelines

A model set of guidelines for RESTful APIs and Events, created by Zalando

The OpenAPI Specification Repository

Style guides for Google-originated open-source projects

Quick Overview

The WhiteHouse/api-standards repository contains a set of guidelines and best practices for designing and implementing APIs within the U.S. government. These standards aim to promote consistency, interoperability, and ease of use across various government agencies' APIs, ensuring a better experience for developers and end-users.

Pros

  • Promotes consistency and standardization across government APIs
  • Improves developer experience and reduces learning curve for working with different agency APIs
  • Encourages best practices in API design, security, and documentation
  • Facilitates interoperability between different government systems and services

Cons

  • May not be suitable for all types of APIs or specific agency requirements
  • Could potentially limit innovation if applied too rigidly
  • Requires ongoing maintenance and updates to keep up with evolving API technologies and practices
  • May face challenges in widespread adoption across all government agencies

Getting Started

To get started with the WhiteHouse API standards:

  1. Visit the repository at https://github.com/WhiteHouse/api-standards
  2. Read through the README.md file for an overview of the standards
  3. Explore the individual markdown files in the repository for detailed guidelines on specific topics
  4. Consider implementing these standards in your own API development projects within government agencies
  5. Contribute to the project by submitting issues or pull requests for improvements or updates to the standards

Competitor Comparisons

Microsoft REST API Guidelines

Pros of api-guidelines

  • More comprehensive and detailed, covering a wider range of API design topics
  • Regularly updated with contributions from the community
  • Includes practical examples and code snippets for better understanding

Cons of api-guidelines

  • May be overwhelming for beginners due to its extensive content
  • Primarily focused on Microsoft's REST API design principles, which may not be universally applicable
  • Requires more time to read and implement due to its length and complexity

Code Comparison

api-standards:

GET /articles?page=2&per_page=10

api-guidelines:

GET /articles?$skip=10&$top=10
GET /articles?$filter=publishedDate ge 2021-01-01

The api-guidelines example demonstrates more advanced querying capabilities, including filtering and pagination using OData-style parameters.

Summary

While api-standards provides a concise set of guidelines for government APIs, api-guidelines offers a more comprehensive and detailed approach to API design. The Microsoft repository is better suited for complex enterprise applications, whereas the WhiteHouse repository focuses on simplicity and consistency for government services. Both repositories have their merits, and the choice between them depends on the specific needs and complexity of the API project.

A model set of guidelines for RESTful APIs and Events, created by Zalando

Pros of restful-api-guidelines

  • More comprehensive and detailed guidelines, covering a wider range of API design aspects
  • Regularly updated and maintained by a large community of contributors
  • Includes practical examples and code snippets for better understanding

Cons of restful-api-guidelines

  • More complex and potentially overwhelming for beginners or smaller projects
  • Some guidelines may be specific to Zalando's ecosystem and not universally applicable
  • Requires more time and effort to fully implement and adhere to all guidelines

Code comparison

restful-api-guidelines:

paths:
  /articles:
    get:
      summary: List articles
      responses:
        200:
          description: Successful response
          content:
            application/json:    
              schema:
                $ref: '#/components/schemas/ArticleList'

api-standards:

{
  "pagination": {
    "count": 100,
    "page": 4,
    "per_page": 25,
    "pages": 4,
    "next": "/articles?page=5&per_page=25",
    "prev": "/articles?page=3&per_page=25"
  },
  "data": [
    {
      "id": "1234",
      "title": "Sample Article"
    }
  ]
}

The code comparison shows that restful-api-guidelines uses OpenAPI specification for defining API endpoints, while api-standards focuses on response structure and pagination.

The OpenAPI Specification Repository

Pros of OpenAPI-Specification

  • More comprehensive and detailed specification for describing RESTful APIs
  • Widely adopted industry standard with extensive tooling support
  • Machine-readable format enables automatic code generation and documentation

Cons of OpenAPI-Specification

  • More complex and potentially overwhelming for simple API designs
  • Requires more effort to create and maintain compared to simpler guidelines
  • May not cover all aspects of API design and governance

Code Comparison

api-standards:

No specific code examples provided in the repository

OpenAPI-Specification:

openapi: 3.0.0
info:
  title: Sample API
  version: 1.0.0
paths:
  /users:
    get:
      summary: Returns a list of users

Summary

The api-standards repository provides high-level guidelines for API design and best practices, focusing on general principles and recommendations. It's more suitable for organizations looking to establish basic API standards.

OpenAPI-Specification, on the other hand, offers a detailed, structured approach to describing RESTful APIs. It provides a machine-readable format that enables automatic code generation, documentation, and testing. While more complex, it offers greater flexibility and tooling support for API development and management.

The choice between the two depends on the organization's needs, existing infrastructure, and desired level of API standardization and automation.

Style guides for Google-originated open-source projects

Pros of styleguide

  • Covers a wider range of programming languages and style guidelines
  • More comprehensive and detailed, addressing various aspects of coding practices
  • Regularly updated and maintained by Google's engineering team

Cons of styleguide

  • May be overly complex for smaller projects or teams
  • Some guidelines might be specific to Google's internal practices and not universally applicable
  • Lacks focus on API-specific standards and best practices

Code Comparison

styleguide (Python):

def SampleFunction(a, b):
    """A brief description of the function.

    Args:
      a: First argument description.
      b: Second argument description.

    Returns:
      Description of the return value.
    """
    return a + b

api-standards (JSON):

{
  "id": 1234,
  "name": "Example Resource",
  "created_at": "2023-05-15T14:30:00Z",
  "updated_at": "2023-05-15T14:30:00Z"
}

Summary

styleguide offers a broader scope of coding standards across multiple languages, while api-standards focuses specifically on RESTful API design and implementation. styleguide provides more detailed guidelines but may be overwhelming for smaller teams, whereas api-standards offers a concise set of best practices for API development. The choice between the two depends on the project's needs and scope.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

White House Web API Standards

Guidelines

This document provides guidelines and examples for White House Web APIs, encouraging consistency, maintainability, and best practices across applications. White House APIs aim to balance a truly RESTful API interface with a positive developer experience (DX).

This document borrows heavily from:

Pragmatic REST

These guidelines aim to support a truly RESTful API. Here are a few exceptions:

RESTful URLs

General guidelines for RESTful URLs

  • A URL identifies a resource.
  • URLs should include nouns, not verbs.
  • Use plural nouns only for consistency (no singular nouns).
  • Use HTTP verbs (GET, POST, PUT, DELETE) to operate on the collections and elements.
  • You shouldn’t need to go deeper than resource/identifier/resource.
  • Put the version number at the base of your URL, for example http://example.com/v1/path/to/resource.
  • URL v. header:
    • If it changes the logic you write to handle the response, put it in the URL.
    • If it doesn’t change the logic for each response, like OAuth info, put it in the header.
  • Specify optional fields in a comma separated list.
  • Formats should be in the form of api/v2/resource/{id}.json

Good URL examples

Bad URL examples

HTTP Verbs

HTTP verbs, or methods, should be used in compliance with their definitions under the HTTP/1.1 standard. The action taken on the representation will be contextual to the media type being worked on and its current state. Here's an example of how HTTP verbs map to create, read, update, delete operations in a particular context:

HTTP METHODPOSTGETPUTDELETE
CRUD OPCREATEREADUPDATEDELETE
/dogsCreate new dogsList dogsBulk updateDelete all dogs
/dogs/1234ErrorShow BoIf exists, update Bo; If not, errorDelete Bo

(Example from Web API Design, by Brian Mulloy, Apigee.)

Responses

  • No values in keys
  • No internal-specific names (e.g. "node" and "taxonomy term")
  • Metadata should only contain direct properties of the response set, not properties of the members of the response set

Good examples

No values in keys:

"tags": [
  {"id": "125", "name": "Environment"},
  {"id": "834", "name": "Water Quality"}
],

Bad examples

Values in keys:

"tags": [
  {"125": "Environment"},
  {"834": "Water Quality"}
],

Error handling

Error responses should include a common HTTP status code, message for the developer, message for the end-user (when appropriate), internal error code (corresponding to some specific internally determined ID), links where developers can find more info. For example:

{
  "status" : 400,
  "developerMessage" : "Verbose, plain language description of the problem. Provide developers
   suggestions about how to solve their problems here",
  "userMessage" : "This is a message that can be passed along to end-users, if needed.",
  "errorCode" : "444444",
  "moreInfo" : "http://www.example.gov/developer/path/to/help/for/444444,
   http://drupal.org/node/444444",
}

Use three simple, common response codes indicating (1) success, (2) failure due to client-side problem, (3) failure due to server-side problem:

  • 200 - OK
  • 400 - Bad Request
  • 500 - Internal Server Error

Versions

  • Never release an API without a version number.
  • Versions should be integers, not decimal numbers, prefixed with ‘v’. For example:
    • Good: v1, v2, v3
    • Bad: v-1.1, v1.2, 1.3
  • Maintain APIs at least one version back.

Record limits

  • If no limit is specified, return results with a default limit.
  • To get records 51 through 75 do this:

Information about record limits and total available count should also be included in the response. Example:

{
    "metadata": {
        "resultset": {
            "count": 227,
            "offset": 25,
            "limit": 25
        }
    },
    "results": []
}

Request & Response Examples

API Resources

GET /magazines

Example: http://example.gov/api/v1/magazines.json

Response body:

{
    "metadata": {
        "resultset": {
            "count": 123,
            "offset": 0,
            "limit": 10
        }
    },
    "results": [
        {
            "id": "1234",
            "type": "magazine",
            "title": "Public Water Systems",
            "tags": [
                {"id": "125", "name": "Environment"},
                {"id": "834", "name": "Water Quality"}
            ],
            "created": "1231621302"
        },
        {
            "id": 2351,
            "type": "magazine",
            "title": "Public Schools",
            "tags": [
                {"id": "125", "name": "Elementary"},
                {"id": "834", "name": "Charter Schools"}
            ],
            "created": "126251302"
        }
        {
            "id": 2351,
            "type": "magazine",
            "title": "Public Schools",
            "tags": [
                {"id": "125", "name": "Pre-school"},
            ],
            "created": "126251302"
        }
    ]
}

GET /magazines/[id]

Example: http://example.gov/api/v1/magazines/[id].json

Response body:

{
    "id": "1234",
    "type": "magazine",
    "title": "Public Water Systems",
    "tags": [
        {"id": "125", "name": "Environment"},
        {"id": "834", "name": "Water Quality"}
    ],
    "created": "1231621302"
}

POST /magazines/[id]/articles

Example: Create – POST http://example.gov/api/v1/magazines/[id]/articles

Request body:

[
    {
        "title": "Raising Revenue",
        "author_first_name": "Jane",
        "author_last_name": "Smith",
        "author_email": "jane.smith@example.gov",
        "year": "2012",
        "month": "August",
        "day": "18",
        "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam eget ante ut augue scelerisque ornare. Aliquam tempus rhoncus quam vel luctus. Sed scelerisque fermentum fringilla. Suspendisse tincidunt nisl a metus feugiat vitae vestibulum enim vulputate. Quisque vehicula dictum elit, vitae cursus libero auctor sed. Vestibulum fermentum elementum nunc. Proin aliquam erat in turpis vehicula sit amet tristique lorem blandit. Nam augue est, bibendum et ultrices non, interdum in est. Quisque gravida orci lobortis... "
    }
]

Mock Responses

It is suggested that each resource accept a 'mock' parameter on the testing server. Passing this parameter should return a mock data response (bypassing the backend).

Implementing this feature early in development ensures that the API will exhibit consistent behavior, supporting a test driven development methodology.

Note: If the mock parameter is included in a request to the production environment, an error should be raised.

JSONP

JSONP is easiest explained with an example. Here's one from StackOverflow:

Say you're on domain abc.com, and you want to make a request to domain xyz.com. To do so, you need to cross domain boundaries, a no-no in most of browserland.

The one item that bypasses this limitation is <script> tags. When you use a script tag, the domain limitation is ignored, but under normal circumstances, you can't really DO anything with the results, the script just gets evaluated.

Enter JSONP. When you make your request to a server that is JSONP enabled, you pass a special parameter that tells the server a little bit about your page. That way, the server is able to nicely wrap up its response in a way that your page can handle.

For example, say the server expects a parameter called "callback" to enable its JSONP capabilities. Then your request would look like:

    http://www.xyz.com/sample.aspx?callback=mycallback

Without JSONP, this might return some basic javascript object, like so:

    { foo: 'bar' }

However, with JSONP, when the server receives the "callback" parameter, it wraps up the result a little differently, returning something like this:

    mycallback({ foo: 'bar' });

As you can see, it will now invoke the method you specified. So, in your page, you define the callback function:

    mycallback = function(data){
        alert(data.foo);
    };

http://stackoverflow.com/questions/2067472/what-is-jsonp-all-about?answertab=votes#tab-top