Skip to content

A seed project for creating APIs that can be run locally or hosted in webtask.io

Notifications You must be signed in to change notification settings

alejofernandez/webtask-api-boilerplate

Repository files navigation

webtask-api-boilerplate

This is a very simple opinionated seed/skeleton project to demo how to build an API and bundle it into a single file, to run it locally or host it in a webtask.io container.

Install global modules

  • npm install -g gulp
  • npm install -g wt-cli

Install local modules

  • npm install

Create your webtask profile and configure your token

  • wt init => then follow instructions
  • wt profile get default => copy the token

default profile

  • open ./config/webtask.config.js and configure the webtaskToken property with your token

To run the API locally

  • gulp run or
  • gulp debug

To deploy the API as a webtask

  • gulp deployWebtask

Opinionated API design

This boilerplate uses webpack for bundling the API and gulp for build/deploy automation. API source code was written in ES6, it uses Express.js for the web stack and MongoDb as repository.

This API tries to implement a simplified version of the REST design pattern, following the guidelines described by DDD. The communication flow between different layers of the API is:

{Http requests} => [Controller] => [Service] => [Repository] => {database}

Layer responsibilities in this API

  • Controller: handles http methods dispatching operations to the service layer and it does the translation between requests/responses and domain model entities.
  • Service: implements the business logic of the domain model.
  • Repository: handles the persistency of the domain model.

How to hack this repo

  1. Edit your configuration files for setting up secrets and parameters.
  2. Create a route installers for your API and define all routes you want to implement.
  3. Create a controller for handling your routes.
  4. Create a service for implementing your business logic.
  5. Create a repository for storing the domain model.
  6. TBD: Add unit tests for your controllers and services.
  7. TBD: Add integration tests for your repositories.
  8. Run/debug your api locally.
  9. Deploy your api to webtask.io.

Roadmap

  • Add tests and a gulp task for running them and a configuration file for tests
  • Add an auto reload task for local development
  • Add an auto re-deploy task and stream logs to the console for 100% remote development
  • Validate required modules against https://tehsis.github.io/webtaskio-canirequire/ as a part of the build
  • Refactor the gulpfile into different plugins for future publishing

deploy

About

A seed project for creating APIs that can be run locally or hosted in webtask.io

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published