Creating an API

Published at: April 4, 2018, 3:34 p.m. in the Documentation

To begin, you must be registered and upload the SSH Keys.

Creating an API

To do this, click on the Create new API button on the main page or in the Marketplace.
Next, enter the name of the API, for example "MyFirstAPI" and a summary description of the project.

Smappi will create your Git repository and launch the container with your API.
After creating, you will see the address of the Git repository, the SSH key created earlier is used for authorization.
In the future, you can find the address of the repository on the page of your project, in the "Source" tab.

Writing an API

Clone the repository and edit the file "api.js":

/**
 * Example of API method
 *
 * @param {String} name
 *
 * @example
 *   hello("Smappi");
 *   // => "Hello, Smappi!"
 */
function hello (name) {
    return "Hello, " + name + "!";
}

module.exports = { hello };

As you can see, everything is very simple.

Local development and debugging of your API

To do this, you need to install Smappi SDK globally:

sudo npm install -g smappi

Now start the local server for development:

smappi run
> Smappi Server running at http://localhost:8000/

Go to URL http://localhost:8000/hello?name=friend and see the following:

"Hello, friend!"

Great, it works!

Send all the changes to Smappi

git commit -m "Created the method hello as sample"
git push

After that, you will be asked to add news about the changes in your API.
In the same time, Smappi will run the tests, build documentation for you from the docstrings (JSDoc).

Additionally

Please read the extended version of the article: Create you first API by example of IMDB parser.