thatjill
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Standards for API Integrations in the Nitro Ecosystem # Summary Here we define a streamlined and standardized way to integrate with external APIs using net-http with a thin wrapper to ensure proper error handling and reporting. This will provide developers with a clear foundation for API integrations, catalyze smoother collaboration across teams, reduce friction during onboarding, improve maintainability, and fortify the overall resilience of the Nitro ecosystem. # Motivation [In August 2023, we faced a production incident arising from an external API call.](https://github.com/powerhome/incidents/commit/651f573fef67c116b85bcdb5ca431d639a74c925?short_path=35f03c9#diff-35f03c98fc83b3a2e1ad4ef130bc7d8d00a4157e3fb4b26c1dbb62a23eff5398) We discovered that we were making many concurrent requests that took 60 seconds to time out, placing large load on web servers. Additionally, long running transactions / metrics on the API were not getting reported to New Relic, which made the incident take longer to pinpoint and debug. The results of this outage indicated that we missed some fundamental considerations and edge cases for this endpoint, but they could easily have been missed for others. In the dynamic landscape of our development environment, different teams have organically adopted distinct tools, often driven by the preexistence API clients in their respective domains. While this decentralized approach initially addressed immediate needs, it has inadvertently led to a proliferation of varied methods to accomplish essentially the same tasks. It also propagated some unwanted behaviors; if one integration missed proper consideration of timeouts or reporting, that behavior could get passed down to subsequent integrations that modeled their usage after it. The divergence and lack of clear guidelines has already played a role in production outages. It has also resulted in an inconsistent codebase, presenting challenges in terms of maintainability, collaboration, and strong standards. The absence of a unified approach has made it difficult for developers to seamlessly transition between different components, hampered efficiency, and contributed to a higher cognitive load. ## Current Scenario In a recent nitro-web survey, we counted at least 48 instances of external API calls with varying clients: * 20 use Net::HTTP * 15 use HTTParty * 9 use RestClient * 2 use Excon * 2 use gems specific to their integration Notably, the majority operate under basic use cases, embodying straightforward integrations. There are two complicated or more restricted circumstances: 1. [Greensky] this issue is due to our integration partner's failure to adhere to [HTTP guidelines around case sensitivity for headers](https://www.rfc-editor.org/rfc/rfc7540#section-8.1.2). In this case, the team decided to go with Excon because that gem does not perform string-casting on headers. In this specific case, Excon was a win, but this is actually a drawback to Excon for most use cases. 2. [Run Payments] This API requires the use of a short-expiring token (one with an expiration date of 1 hour.) The team has outlined their plan [here](https://hackmd.io/1vFP4RgKS9-ri7K8dRjDEw). In this case, they opted to use Net::HTTP and database the token as they routinely update it. Given this context, our aim is straightforward: establish a consistent approach and guidelines for Nitro's external API integrations. This standardization encompasses fundamental aspects like timeouts, elegant failure handling, and issue notifications, aiming to streamline our ecosystem and simplify the API integration process. # Solution ### _net-http_ Moving forward, we propose a consolidated approach for handling APIs within the Nitro ecosystem. Our solution involves adopting net-http as the default for API interactions. Using this gem is the most straightforward solution with the least path of resistance for conversion in nitro-web. net-http is already included in ruby and is supported as part of that language. In the event that ruby maintainers choose an alternative to net-http, it means that other common APIs that wrap net-http (including HTTParty and RestClient) would also need to find alternatives. At best, their solutions would mean more upgrades for us; at worst, they may introduce breaking changes, awkward upgrade paths, and assertions that no longer align with our own. Since net-http comes bundled with ruby and is the default gem for requests, adopting this as the standard means we do not have to concern ourselves with additional maintenance costs. Additionally, we have evidence of other successful enterprise-level companies (Shopify, for example) that establish their standards around net-http; going through another package may just be introducing an unnecessary layer of abstraction. ### _api_chai_ To enhance usability and resilience, we will implement a straightforward layer between API calls and net-http, which we will call [api_chai](https://rubygems.org/gems/api_chai). Once this layer is equipped, developers will be expected to use net-http through api_chai for their external API integrations. The intermediary layer serves a triple purpose. First, it establishes a default timeout for API requests, ensuring we aren't waiting too long with failed connections or non-responses. Second, it will integrate with New Relic and Sentry to ensure prompt issue reporting, providing real-time insights into failure points. Finally, it codifies graceful error handling, preventing disruptions and allowing a smooth flow of information back to the caller. By standardizing on net-http and implementing the api_chai lightweight layer, we aim to simplify API interactions across the board, making our system more robust, reliable, and developer-friendly, and avoiding incidents where failures cause production outages or hamper debugging tools. # Implementation Plan This structured plan provides a phased and collaborative approach, leveraging HFH support, iterative testing, and detailed transition guides to ensure a smooth adoption of the net-http standard and associated tools. 1. Establish Standard: Clearly define and communicate the net-http standard for all teams during the transition, ensuring a unified approach. 2. Develop an api_chai component: This will be created in nitro-web and used as a versatile stopgap for easy testing and implementation throughout the transition period. 3. Implement api_chai for net-http calls: Initiate the transition by implementing api_chai for existing net-http calls, starting with nitro_search in components/nitro_search/lib/tasks/nitro_search.rake. HFH will lead initial implementations and extend them to other instances inside of nitro-web. Facilitate testing by involving one or two teams who would implement changes in their domains, gathering valuable feedback. HFH will publish a comprehensive transition guide, aiding teams in adopting api_chai. 4. Migrate HTTParty Use Cases: Begin migrating HTTParty use cases, starting with core_models/suppliers in components/core_models/lib/core_models/suppliers/clients/distributor.rb. Once they have migrated a few components as examples, HFH will spearhead initial conversions and provide detailed transition guides for wider team adoption. 5. Migrate RestClient Use Cases: Address RestClient use cases, beginning with components like components/mdm/lib/mdm/jamf/jamf_api.rb. HFH to handle initial migrations and guide teams through the transition, again publishing transition guides that other teams can rely on. 6. Migrate Excon Use Cases: Migrate the existing Excon use cases, with HFH taking the lead in the transition. 7. External Client Support: Ensure adaptability by allowing external clients to be supported, accommodating unique use cases. The integration will be something like this: ```ruby= ApiChai.with_external_client do GemSpecificToIntegration.call(my_args_here) end ``` This would allow us to continue to use gems specific to integrations, while still giving us all the benefits of monitoring, etc that the ApiChai wrapper provides. 8. Extract api_chai to power-tools: Elevate api_chai by extracting it into power-tools, extending its accessibility and utility across the entire Nitro ecosystem. # Drawbacks / Alternatives _net-http is unwieldy_ As one developer put it: > nobody likes writing net-http code. And it’s easy to see why, just look at this cheatsheet: its API is convoluted, verbose, needlessly OO-heavy (why does one need an exception for every HTTP error status code…), it just does not enact joy. The good news is that we can address the most frustrating parts of this integration via the thin wrapper that we already plan to use to help us manage our other concerns. _Build vs Buy / Other API Clients_ A similar argument is that instead of directly referencing net-http, there is always the option to use an existing, well-documented and supported library that already implements the standards we require. For example, HTTParty, which has long been a staple, much-loved and utilized gem due to ease of use. However, HTTParty and RestClient, our second and third most prolific clients, are just a user-friendly wrapper for net-http, so we're not really getting the intended benefit if we (1) have mostly straightforward implementations already and (2) have a thin layer that was already written to be user-friendly and helpful. These other clients also avoid being opinionated by way of enforcing reporting to any specific third-party (NewRelic) or enforcing shorter default timeouts, so they don't really provide the desired behavior we're looking for. Using net-http encourages us to continue the path of straightforward, simplistic code and behavior. ### How We Teach This 1. API Standards in BT Handbook & api_chai We'll integrate API standards into our BT Handbook for easy access and reference. These standards will emphasize practical implementation by pointing to api_chai-specific documentation, providing examples to ensure consistency across projects. 2. Migration Guides for nitro-web To make transitions smoother, we will develop straightforward migration guides. These guides will address common challenges, offering step-by-step instructions. Interactive elements like code snippets and troubleshooting tips will be included, ensuring developers have practical support during the migration process. 3. Lunch & Learn Session with Summary Publication We will offer Lunch & Learn sessions designed to keep the team in the loop with the latest in API practices and chat about it real-time. These sessions aim to create an open space for questions, collaboration, and continuous learning, fostering a more connected and informed development community. For those unable to attend, we'll publish a concise summary capturing key insights, takeaways, and any discussions.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully