Testing Twilio SMS Requests for .NET Applications with the Rider REST Client
Time to read: 3 minutes
We can use the Twilio Nuget package to write applications that work with the Twilio SMS API, but what if we want to experiment with the API in our IDE? If that IDE happens to be JetBrains Rider, there is an easy way to do this.
Rider is a cross-platform .NET IDE that builds on technology from ReSharper and IntelliJ IDEA. This provides the best of two worlds: excellent .NET code inspections, navigation and refactorings, plus the front-end features from a mature IDE with a vibrant ecosystem. Or in other words: if we want to test a Twilio SMS API call from within our IDE, we can use the built-in REST client for that.
After starting Rider and creating or opening a solution, open the REST client from Tools | Test RESTful Web Service. This will open a new tool window where we can craft HTTP requests.
This tool window allows us to select the HTTP method and set the host and path to be invoked. We can also add header data, query string parameters or a request body to be sent to the API.
Creating an HTTP request
Let’s see if we can send an SMS message from within our IDE. According to the API docs, we’ll need to POST to https://api.twilio.com/2010-04-01/Accounts/[AccountSid]/Messages and addFrom
, To
and Body
parameters.
We could try invoking this request right now, but there is one key ingredient missing: authentication. Twilio requires us to use basic authentication using our AccountSid and AuthToken as credentials. We can find these in the Twilio Console and then use Rider’s generate credentials toolbar button to add the necessary header:
After clicking OK, Rider adds an Authorization header and we can now invoke our request. If all went well, we will see the result of our API call and our phone should notify us we have a new SMS message.
We got back an XML response but adding the Accept: application/json
header will return JSON. The toolbar buttons allow us to reformat the response (which may be useful if the server stripped whitespace), open the response in a separate window, or export the response to a file. The various tabs let us inspect or add cookies, response headers etc.
Re-using requests
While Rider is running it keeps track of all requests that have been made previously. We can re-issue previous requests quite easily; just make sure not to spam yourself or a colleague with test SMS messages!
We can also export requests from the toolbar, including headers and request parameters, to a file that can be imported again later on. The generated files are XML files which we can hand-edit to our needs. Here’s an example send-sms.xml
which contains the request above:
The export/import functionality allows us to create a series of HTTP requests that can be used during development and share with team members to quickly test common requests against the Twilio API.
Wrapping up
It’s quite useful to have a built-in REST client in an IDE like JetBrains Rider. We can test API calls against a service like Twilio while we are developing an application that uses these API’s.
Give it a try! And if you have any questions on Rider, hit me up on Twitter.
Related Posts
Related Resources
Twilio Docs
From APIs to SDKs to sample apps
API reference documentation, SDKs, helper libraries, quickstarts, and tutorials for your language and platform.
Resource Center
The latest ebooks, industry reports, and webinars
Learn from customer engagement experts to improve your own communication.
Ahoy
Twilio's developer community hub
Best practices, code samples, and inspiration to build communications and digital engagement experiences.