Jump to content
  • My first Node.js TIBCO Cloud? Integration app


    Deepesh Tiwari

    Node.js on TCI

    1. Getting started
    2. Prerequisites
    3. My first Node.js app
    4. Deploy your first Node.js app
    5. Test your Node.js app
    6. Manage your Node.js apps
    7. Adding dependencies to your app
    8. Run your app locally
    9. Understanding the generated code
    10. Advanced topics
    11. Best practices
    12. Resources

    Let?s build our first Node.js app on TIBCO Cloud? Integration. This part of the tutorial will walk through creating the Node.js from an existing API specification. For more information on how to create an API specification, see Modeling an API

    The API

    As with every programming language and pretty much every program, the first thing you create is an Hello World example. This isn?t going to be any different, so below is the Swagger definition of the API we?re going to build. You can either create it in the Modeler yourself or download it from the resources section and import it into TIBCO Cloud Integration.

     

    The API has one GET method called greeting and takes a parameter called name

     {   "swagger": "2.0",   "info": {       "version": "1.0.0",       "title": "HelloWorld",       "x-lastModified": "Jul 29, 2017 23:13PM PST"   },   "paths": {       "/greeting/{name}": {           "get": {               "produces" : [                    "application/json"               ],               "responses": {                   "200": {                       "description": "Success response",                       "schema": {                           "$ref": "#/definitions/GetResponseSchema"                       },                       "examples": {                           "application/json": {                                "message": "Hello World!"                           }                       }                   }               },               "parameters": [ {                   "name": "name",                   "in": "path",                   "description": "",                   "required": true,                   "type": "string",                   "format": ""               } ]           }       }   },   "definitions": {       "GetResponseSchema": {           "type": "object",           "properties": {               "message": {                   "type": "string",                   "default": "Hello World!"               }           }       }   } }

     

    Generate the code

    To generate the code from the API specification, log in to TIBCO Cloud Integration and go to the API specs page.

     

    hamburger.png.142067b4f3aa4ee8b81968669372d74e.png

     

    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.  This will give you a zip file containing the generated code and a manifest.json file that is needed when you want to push the app to TCI.

    Updating the code

    Unzip the zip file and you?ll see a bunch of files (you can get the zip file of this sample from the resources section). The structure of the folder will be very similar to what we have below:

     ????hello_world_nodejs_app_1501395218703 ?   |???manifest.json ?   ????hello_world_nodejs_app_1501395218703 |       |???.eslintignore |       |???.eslintrc |       |???.npmignore |       |???package.json |       |???README.md |       |???server.js ?       ????config ?       ?   ????swagger.json ?       ????data ?       ?   |???mockgen.js ?       ?   ????greeting ?       ?       ????{name}.js ?       ????handlers ?       ?   ????greeting ?       ?       ????{name}.js ?       ????tests ?       ?   ????greeting ?       ?       ????{name}.js ?       ????util ?           ????logger.js

     

    We?ll not go over all the files right now, but we do want to make a small change the to {name}.js file in the data/greeting folder. We?ll change it in such a way that the name we pass as a parameter will be used in the response we get back. The generated code will be something like:

     Mockgen().responses({     path: '/greeting/{name}',     operation: 'get',     response: '200' }, callback);

     

    And we?ll replace that with:

     var data = JSON.parse('{"responses": {"message": "Hello ' + req.params.name + '"}}'); callback(null,data)

     

    Instead of a generated mock response, it will respond back with Hello and the name you put in.

    I got this! Let's deploy!


    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...