Skip to main content
Building REST Services in TIBCO Cloud Integration
  1. Blog/

Building REST Services in TIBCO Cloud Integration

·4 mins·

You shouldn’t have to be a Swagger expert to design and build an API. Creating an API from scratch can be a difficult task, so what if you could do it without writing a line of code?

The Web Integrator in TIBCO Cloud Integration is an API-led platform that makes it straightforward to get started building REST services. Think about the message you want to receive and the response you want to send back — that’s all you need to define your API.

What we’re building
#

A FlightBookings app that sends an email confirmation to the user requesting air travel.

Create the app
#

Like every app on TIBCO Cloud Integration, start with the orange Create button. The Web Integrator is powered by TIBCO’s OSS Project Flogo and the mascot (Flynn) is in the interface. Click on Create a Web Integrator App to get started.

Create the flow
#

Click Create a flow and select Rest Trigger. This is where you configure your API. The resource path is what your API listens on — best practice is to use the plural form of a noun (books, apps, or in our case, flightbookings). The HTTP methods supported by Web Integrator are:

  • GET: Get the resource specified (e.g. get a single book or get all books)
  • POST: Create a new resource of the object (e.g. create a new flightbooking)
  • PUT: Update a resource or create a new one if it doesn’t exist yet (e.g. update an app or create a new one)
  • DELETE: Remove the resource (e.g. delete the cookie)

We’re creating new flightbookings, so the method is POST. Rather than writing JSON schema by hand, the Web Integrator lets you paste a sample message for input and output. Copy this into the input box and click Create:

{
"Class": "string",
"DepartureDate": "2017-05-27",
"Destination": "string",
"FirstName": "string",
"EmailAddress": "string"
}

Obviously you can have more fields, but this is good enough for now

Implement logic
#

Now for the business logic. Click on the newly created flow and you’ll see a canvas with two tiles: ReceiveHTTPMessage (triggers the flow) and ReplyToHTTPMessage (sends a response to the client). We’ll do three things:

  1. Add a log tile to log that a new message arrived
  2. Add an email tile to send a confirmation
  3. Update the ReplyToHTTPMessage to send back the data we need

Adding a log tile
#

Click on ReplyToHTTPMessage and drag it two spaces over to make room for new tiles.

Click the first empty tile and select Log Message. It needs an input — on the Input click message to craft the log message. There are plenty of functions available, but we’ll use a simple string concatenation. You can type in the textbox or click on parameters and functions on the right side. Or just copy this:

string.concat("A new booking request has arrived for ", $TriggerData.body.FirstName)

This function concatenates a string with the FirstName passed in as a parameter

Sending an email
#

For the email step, I covered the Send Mail activity setup in a previous post so I’ll skip the connection details. The email activity needs 4 inputs:

  1. sender: who the message comes from (e.g. some@email.com)
  2. recipients: the email address from the request. Click on recipients and search for EmailAddress inside $TriggerData (or use `$TriggerData.body.EmailAddress`)
  3. subject: the subject line (e.g. thank you for requesting a flight)
  4. message: the email body, using concat again to personalize it:
string.concat("Dear ", string.concat($TriggerData.body.FirstName, ". Thank you for requesting a flight. Please note we'll take care of it soon!"))

Updating the ReplyToHTTPMessage
#

Instead of echoing back the input, update the Input Settings with a new response sample. We want to reply with the FirstName, a unique identifier, and the current date:

{
"FirstName": "string",
"ID": "string",
"Date": "string"
}

Paste that in and the Input tab fields update automatically. Map them:

  1. FirstName: $TriggerData.body.FirstName
  2. ID: number.random(999999)
  3. Date: datetime.currentDate()

Push your app
#

Everything’s mapped and configured. Click the blue Push app button to deploy.

Test it
#

After pushing, you’ll be back on the Apps page. Click View and Test 1 Endpoint then View API to open the test page. On the POST method, the only required item is the body:

{
"Class": "string",
"DepartureDate": "string",
"Destination": "string",
"EmailAddress": "string",
"FirstName": "string"
}

Be sure to replace the value of EmailAddress with an actual email address to make sure you see the result :)

The response body should look something like:

{
"Date": "2017-08-15+00:00",
"FirstName": "string",
"ID": 623436
}

That’s it
#

A few steps and you’ve got a working API for flight bookings. As always let me know your thoughts on this tutorial either by commenting below or posting something on the TIBCO Community!

Related

How To Combine APIs With Flogo Apps In TIBCO Cloud Integration

·4 mins
In 2002 Jeff Bezos issued a mandate that would change the world forever. At the very least it brought a massive change to how data is reused on the Internet: All teams will henceforth expose their data and functionality through service interfaces. Teams must communicate with each other through these interfaces. There will be no other form of inter-process communication allowed: no direct linking, no direct reads of another team’s data store, no shared-memory model, no back-doors whatsoever. The only communication allowed is via service interface calls over the network. It doesn’t matter what technology they use. All service interfaces, without exception, must be designed from the ground up to be externalizable. That is to say, the team must plan and design to be able to expose the interface to developers in the outside world. No exceptions. Anyone who doesn’t do this will be fired. Thank you; have a nice day! That mandate kicked off a lot of what we now call the API economy. Many enterprises have APIs that deliver data so you can focus on building value rather than figuring out how to get the data. That said, most APIs out there are documented but don’t have a swagger.json you can import directly. The Web Integrator in TIBCO Cloud Integration lets you paste sample messages from API docs and use those as the basis for invoking REST APIs.

How To Connect Google Forms to APIs

·4 mins
Ever wanted to capture data from a form and send it somewhere useful? Google Forms handles the collection side well, but what about routing that data to an API? That’s where TIBCO Cloud Integration comes in.