Introducing Twilio’s OpenAPI Specification Beta

April 19, 2021
Written by
Reviewed by
Shawn Stern
Contributor
Opinions expressed by Twilio contributors are their own
Diane Phan
Twilion
Jon Davis
Twilion

Introducing Twilio's OpenAPI Specification Beta

Whether you are building your first product with Twilio or looking to expand your product offering, you need easy access to tools in the programming languages or environments you use. Today, we are excited to announce that we have open-sourced an OpenAPI specification in Beta for every Twilio API.

For a long time we’ve supported and maintained helper libraries and tooling in a handful of the most popular languages and environments used by developers. We’re now expanding that coverage by providing Twilio API documentation files in accordance with the OpenAPI Specification, an industry-standard format for APIs. This makes it simple for you to auto-generate code so you can easily build with Twilio no matter the language or tools you use.

What you can do with OpenAPI?

Client Library Generation

Using the power of the Twilio OpenAPI specification and open-sourced OpenAPI generator, you can now generate new client libraries. This makes it much more convenient and simpler to use Twilio in your preferred programming language, without writing complex methods and functions. As an example, it is now possible to programmatically build a strongly-typed Rust library for Twilio’s API methods.

use dotenv;
use std::env;
use openapi::apis::{configuration::Configuration, default_api as twilio_api};

#[tokio::main]
async fn main() {
  dotenv::dotenv().expect("Failed to read .env file");
  let account_sid = env::var("TWILIO_ACCOUNT_SID").expect("Failed to parse Account SID");
  let api_key = env::var("TWILIO_API_KEY").expect("Failed to parse API Key");
  let api_key_secret = env::var("TWILIO_API_KEY_SECRET").expect("Failed to parse API Key Secret"); 
  
  let mut twilio_config = Configuration::default();
  // Supply Basic Auth credentials.
  twilio_config.basic_auth = Some((api_key, Some(api_key_secret)));
 
  let balance = twilio_api::fetch_balance(&twilio_config, &account_sid)
    .await
    .unwrap();

  println!("{:?}", balance);
}

To learn more about helper library generation see our OpenAPI Generator Project on GitHub or Twilio docs on helper library generation.

Mock Testing

Using the OpenAPI Specification, you can now mock Twilio’s API to emulate real API calls locally, which makes test suite integration with Twilio faster and less brittle.

For example, you can now easily make a mock server of Twilio’s API portable with Docker.

docker run --init -d -p 4010:4010 stoplight/prism:4 mock -h 0.0.0.0 https://raw.githubusercontent.com/twilio/twilio-oai/main/spec/json/twilio_api_v2010.json

To learn more about mock testing, see our docs.

Postman Support

We have also added support for Postman, which is a free and straightforward development tool for making API calls with a variety of helpful features. Instead of referencing the Twilio Docs and creating your own collection, you can visit the Twilio Postman Collection page where you will find collections maintained by the Twilio team. You can also browse the Twilio Postman APIs visually using Postman.

Twilio Messaging / SMS Collection

Head over to our docs to read more about using Twilio's Postman Collections.

Try it Out!

We can’t wait to see all the amazing things you’ll build with Twilio’s OpenAPI Specification! 🚀

If you want to provide feedback to our team and learn early about upcoming features, request to join our new Twilio Insiders program or reach out to me via email gjones[at]twilio.com.