|
| 1 | +## Nimbella Serverless Cloud |
| 2 | + |
| 3 | +Thank you for trying out Nimbella to deploy a TypeScript serverless project. |
| 4 | + |
| 5 | +### Hello World |
| 6 | +We created a starter project on [GitHub](https://github.com/nimbella/demo-projects/tree/master/hello-typescript). The project consists of the following files: |
| 7 | + |
| 8 | +- [`lib/src/hello/Hello.ts`](https://github.com/nimbella/demo-projects/blob/master/hello-typescript/lib/src/hello/Hello.ts): a sample function which implements a greeting API. |
| 9 | +- [`lib/test/hello/Hello.test.ts`](https://github.com/nimbella/demo-projects/blob/master/hello-typescript/lib/test/hello/Hello.test.ts): a file containing unit tests for the sample function, implemented using [Jest](https://jestjs.io/). |
| 10 | + |
| 11 | +- [`lib/build.sh`](https://github.com/nimbella/demo-projects/blob/master/hello-typescript/lib/build.sh): a build script which runs the TypeScript compiler to generate JavaScript. The compiled output is webpacked, and the result is used to create the serverless API. The webpack configuration is located in [`lib/src/hello/webpack.config.js`](https://github.com/nimbella/demo-projects/blob/master/hello-typescript/lib/src/hello/webpack.config.js). The TypeScript compiler configuration can be found in [`lib/tsconfig.json`](https://github.com/nimbella/demo-projects/blob/master/hello-typescript/lib/tsconfig.json). |
| 12 | + |
| 13 | +- [`packages/hello-ts/hello`](https://github.com/nimbella/demo-projects/tree/master/hello-typescript/packages/hello-ts/hello): a directory which will contain the implementation of a serverless API `/api/hello-ts/hello`. |
| 14 | + - [`build.sh`](https://github.com/nimbella/demo-projects/blob/master/hello-typescript/packages/hello-ts/hello/build.sh): a shell script for Mac and GNU/Linux platforms, to build and package the functions for deployment to the cloud. |
| 15 | + - [`package.json`](https://github.com/nimbella/demo-projects/blob/master/hello-typescript/packages/hello-ts/hello/package.json): this is a Node.js pacakges file to install dependencies. This sample does not require dependencies. |
| 16 | + |
| 17 | +### Install the Nimbella CLI |
| 18 | + |
| 19 | +You will need the Nimbella CLI to get started. |
| 20 | +Please download the CLI specific for your platform from [https://nimbella-apigcp.nimbella.io/login.html?token=_#cli](https://nimbella-apigcp.nimbella.io/login.html?token=_#cli). |
| 21 | + |
| 22 | +Once you install the CLI, you will need to run: |
| 23 | + |
| 24 | +``` |
| 25 | +nim login |
| 26 | +``` |
| 27 | + |
| 28 | +If you do not yet have an account, this will be your opportunity to sign up (it's free and no upfront information is needed except your e-mail or GitHub id). |
| 29 | + |
| 30 | +### Deploy your first project |
| 31 | + |
| 32 | +You are now ready to deploy and run the starter project in three steps. |
| 33 | + |
| 34 | +#### 1. Clone the demo project from GitHub |
| 35 | + |
| 36 | +``` |
| 37 | +git clone git@github.com:nimbella/demo-projects.git |
| 38 | +``` |
| 39 | + |
| 40 | +#### 2. Deploy the project |
| 41 | +``` |
| 42 | +nim project deploy demo-projects/hello-typescript |
| 43 | +``` |
| 44 | + |
| 45 | +You will see output similar to: |
| 46 | + |
| 47 | +``` |
| 48 | +Deploying project '/path/to/demo-projects/hello-typescript' |
| 49 | + to namespace 'example-namespace' |
| 50 | + on host 'https://apigcp.nimbella.io' |
| 51 | +Started running ./build.sh in nimbella/demo-projects/hello-typescript/hello-ts/hello |
| 52 | +Still running ./build.sh in nimbella/demo-projects/hello-typescript/hello-ts/hello |
| 53 | +... |
| 54 | +Finished running ./build.sh in nimbella/demo-projects/hello-typescript/hello-ts/hello |
| 55 | +Deployment status recorded in 'hello-typescript/.nimbella' |
| 56 | +
|
| 57 | +Deployed actions ('nim action get <actionName> --url' for URL): |
| 58 | + - hello-ts/hello |
| 59 | +``` |
| 60 | + |
| 61 | +#### 3. Run your serverless API |
| 62 | + |
| 63 | +``` |
| 64 | +nim action invoke hello-ts/hello --param name World |
| 65 | +``` |
| 66 | + |
| 67 | +This will show the following result: |
| 68 | + |
| 69 | +``` |
| 70 | +{ |
| 71 | + "body": "Hello, World!" |
| 72 | +} |
| 73 | +``` |
| 74 | + |
| 75 | +The API you deployed can be used from the browser or via `curl`, Postman, or your favorite API testing tool. |
| 76 | +To get the URL for the API run the following command. |
| 77 | + |
| 78 | +``` |
| 79 | +nim action get hello-ts/hello --url |
| 80 | +``` |
| 81 | + |
| 82 | +You may pass parameters either as query parameters or as JSON content. Here are two examples using `curl`. |
| 83 | + |
| 84 | +``` |
| 85 | +> curl `nim action get hello-ts/hello --url`?name=typescript |
| 86 | +Hello, typescript! |
| 87 | +``` |
| 88 | + |
| 89 | +``` |
| 90 | +> curl `nim action get hello-ts/hello --url` \ |
| 91 | + -X POST \ |
| 92 | + -H 'content-type: application/json' \ |
| 93 | + -d '{"name":"again"}' |
| 94 | +Hello, again! |
| 95 | +``` |
| 96 | + |
| 97 | +### Running the tests |
| 98 | + |
| 99 | +This example includes unit tests in the `lib/test` directory. You can run the tests as shown below. |
| 100 | + |
| 101 | +``` |
| 102 | +cd lib |
| 103 | +npm install |
| 104 | +npm run test |
| 105 | +``` |
| 106 | + |
| 107 | +### Support and Feature Requests |
| 108 | + |
| 109 | +We welcome your feedback and thoughts on what features will be helpful to make your serverless journey a success. |
| 110 | + |
| 111 | +- For general bugs and enhancements, we suggest opening [an issue on GitHub](https://github.com/nimbella/nimbella-cli/issues/new). |
| 112 | +- For quick questions, you can reach us in [Slack](nimbella-community.slack.com). |
0 commit comments