Introducing Twilio’s Open API 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.

# Dockerfile
# Choose the base image for us to build from.
FROM alpine

# Install dependencies.
RUN apk update && \
 apk add --update git && \
 apk add --update npm && \
 npm i -g @stoplight/prism-cli

# Clone the Twilio OpenAPI spec.
RUN git clone https://github.com/twilio/twilio-oai.git

# Perform preprocessing on the v2010 spec JSON file.
RUN sed -i.bak '/pattern:/d' ./twilio-oai/spec/json/twilio_api_v2010.json && \
 sed -i.bak 's/</Before/' ./twilio-oai/spec/json/twilio_api_v2010.json && \
 sed -i.bak 's/>/After/' ./twilio-oai/spec/json/twilio_api_v2010.json

# Expose the port that Prism runs on.
EXPOSE 4010

# Run Prism!
CMD ["prism", "mock", "-h", "0.0.0.0", "./twilio-oai/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.


This content originally appeared on Twilio Blog and was authored by Gareth Paul Jones

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.

# Dockerfile
# Choose the base image for us to build from.
FROM alpine

# Install dependencies.
RUN apk update && \
 apk add --update git && \
 apk add --update npm && \
 npm i -g @stoplight/prism-cli

# Clone the Twilio OpenAPI spec.
RUN git clone https://github.com/twilio/twilio-oai.git

# Perform preprocessing on the v2010 spec JSON file.
RUN sed -i.bak '/pattern:/d' ./twilio-oai/spec/json/twilio_api_v2010.json && \
 sed -i.bak 's/</Before/' ./twilio-oai/spec/json/twilio_api_v2010.json && \
 sed -i.bak 's/>/After/' ./twilio-oai/spec/json/twilio_api_v2010.json

# Expose the port that Prism runs on.
EXPOSE 4010

# Run Prism!
CMD ["prism", "mock", "-h", "0.0.0.0", "./twilio-oai/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.


This content originally appeared on Twilio Blog and was authored by Gareth Paul Jones


Print Share Comment Cite Upload Translate Updates
APA

Gareth Paul Jones | Sciencx (2021-04-19T18:05:05+00:00) Introducing Twilio’s Open API Specification Beta. Retrieved from https://www.scien.cx/2021/04/19/introducing-twilios-open-api-specification-beta/

MLA
" » Introducing Twilio’s Open API Specification Beta." Gareth Paul Jones | Sciencx - Monday April 19, 2021, https://www.scien.cx/2021/04/19/introducing-twilios-open-api-specification-beta/
HARVARD
Gareth Paul Jones | Sciencx Monday April 19, 2021 » Introducing Twilio’s Open API Specification Beta., viewed ,<https://www.scien.cx/2021/04/19/introducing-twilios-open-api-specification-beta/>
VANCOUVER
Gareth Paul Jones | Sciencx - » Introducing Twilio’s Open API Specification Beta. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/04/19/introducing-twilios-open-api-specification-beta/
CHICAGO
" » Introducing Twilio’s Open API Specification Beta." Gareth Paul Jones | Sciencx - Accessed . https://www.scien.cx/2021/04/19/introducing-twilios-open-api-specification-beta/
IEEE
" » Introducing Twilio’s Open API Specification Beta." Gareth Paul Jones | Sciencx [Online]. Available: https://www.scien.cx/2021/04/19/introducing-twilios-open-api-specification-beta/. [Accessed: ]
rf:citation
» Introducing Twilio’s Open API Specification Beta | Gareth Paul Jones | Sciencx | https://www.scien.cx/2021/04/19/introducing-twilios-open-api-specification-beta/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.