The TIBCO Platform is a real-time, composable data platform that will bring together an evolving set of your TIBCO solutions - and it's available now!
A chart showing the TIBCO Platform vision
Jump to content
Articles
Read more about TIBCO use cases, product features, capabilities and more
  • Advanced API Modeler topics


    Vikas Kumar 9

    Modeling and testing APIs

    1. Getting started
    2. Prerequisites
    3. My first API
    4. Adding resources
    5. Import & Export
    6. Managing API specs
    7. Testing with Mock apps
    8. Advanced topics
     

    Advanced responses

    Remember in the previous step the responses were a little underwhelming? The Mocks apps have a bit more functionality that you can use to change that and have different answers based on your input. With that feature, advanced responses you can customize your response data by using JavaScript.

    Back to the Apps details page, as you?re on the Implementation tab you can see that on the right hand side of the screen (right next to where it says ?No updates to push?), there is a link called Switch to Advanced Responses. As you click on that you turn on the advanced responses for that particular method. As the GET method should be selected, we?ll turn it on for that one. As you hover over the text editor, you?ll see a little blue square with Edit. As you click on that, it will open up the text editor to type. The below JavaScript code check which id was passed in and differs the response based on that.

     if (req.params.id == "12345") {     res.status = 200;     res.body = {         internalID: req.params.id,         title: 'My new book'     }; } else if (req.params.id == "67890") {     res.status = 200;     res.body = {         internalID: req.params.id,         title: 'The other book I could have written'     }; } else {     res.status = 404; }

     

    Click on Save and Update Mock app to make the changes active. From the Apps page, click on View and Test 1 Endpoint and click on View API to see the test page where you can now test your updated app. As you enter 12345 as the id for the GET operation the response should be

     { "internalID": "12345",   "title": "My new book" }

     

    Implement your API

    Creating a Mock app is great as it allow you to focus on the business logic of implementing it, while other can already build their integrations. As you?re done building, the only thing that changes is the URL if you create a completely new app or nothing at all if you replace the existing app. With TIBCO Cloud Integration you have a few options to choose from when implementing your logic.

    In Node.js

    Node.js® is a JavaScript runtime built on Chrome?s V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js? package ecosystem, npm, is the largest ecosystem of open source libraries in the world.

    To generate the code from the API specification, log in to TIBCO Cloud? Integration and go to the API specs page. From there hover over the API specification you want to generate the code for, click on the hamburger menu and click on Generate Node.js code. That will give you a zip file with all the code and a manifest.json file that is needed when you want to push the app to TCI.

    In TIBCO Business Studio - Cloud Edition

    TIBCO Business Studio - Cloud Edition is the Eclipse based IDE for TIBCO Cloud Integration. In that IDE you?ll find an API Explorer that displays the APIs you?ve modeled. This allows you to drag and drop them into your integration project and start implementing from there.

    In TIBCO BusinessWorks Container Edition

    TIBCO BusinessWorks Container Edition also features Business Studio with the same type of API Explorer. From there you can drag and drop them into your integration project and start implementing too! The big difference being where you deploy your app.


    User Feedback

    Recommended Comments

    There are no comments to display.



    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

×
×
  • Create New...