Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Building a Simple Counter App

This tutorial will guide you through building a simple counter API with Kinesis API. You'll create an API endpoint that stores and increments a count value with each request. This is a perfect first project to help you understand the fundamentals of Kinesis API.

Prefer video tutorials? You can follow along with our YouTube walkthrough of this same project.

Prerequisites

Before you begin, you need:

  1. Access to a Kinesis API instance:

  2. A user account with ADMIN or ROOT privileges

  3. Basic understanding of REST APIs and HTTP methods

1. Creating a Project

First, we'll create a project to organize our counter API:

  1. Log in to your Kinesis API instance
  2. Navigate to the Projects page from the main menu
  3. Click "Create a new project" to open the project creation modal
  4. Fill in the following details:
    • Name: "Counter Project"
    • ID: "counter"
    • Description: "A dummy starter project for a counter." (or anything else you want)
    • API Path: "/counter" (this will be the base URL path for all routes in this project) Create Project
  5. Click "Create" to save your project

2. Creating a Collection

Next, we'll create a collection to store our counter data:

  1. From your newly created project page, click "Create New" on the "Collections" section
  2. Fill in the following details:
    • Name: "count"
    • ID: "count"
    • Description: "To store the actual count object." (or anything else you want) Create Collection
  3. Click "Create" to save your collection

Project Page

3. Creating Structures

Now we'll create some structures (fields) to store our counter value:

  1. From the Count collection page, locate the "Structures" section
  2. Click "Create New" to add a structure
  3. Fill in the following details:
    • Name: "id"
    • ID: "id"
    • Description: "" (leave blank or insert anything else)
    • Type: "INTEGER"
    • Min: "0"
    • Max: "1000"
    • Default Value: "0"
    • Required: Check this box
    • Unique: Check this box Create ID Structure
  4. Click "Create" to save the structure
  5. Click "Create New" to add another structure
  6. Fill in the following details:
    • Name: "value"
    • ID: "value"
    • Description: "" (leave blank or insert anything else)
    • Type: "INTEGER"
    • Min: "0"
    • Max: "999999999"
    • Default Value: "0" (to start the counter at zero)
    • Required: Check this box Create Value Structure
  7. Click "Create" to save the structure

Collection Page

4. Creating Data

Now we'll create an initial data object with our counter:

  1. Navigate to the "Data" section in the top navigation bar
  2. Select your project and then the "Count" collection
  3. Click "Create New" to create a data object
  4. Add a nickname (optional)
  5. For the "id" field, enter: "0"
  6. For the "value" field, enter: "0" Create Data
  7. Click "Create" to save your data object

Data Page

5. Creating a Route

Now we'll create a route that increments the counter:

  1. Navigate to "Routes" in the top navigation bar
  2. Select your project
  3. Click "Create New" to create a route
  4. Fill in the route details:
    • Route ID: "GET_COUNTER"
    • Route Path: "/get"
    • HTTP Method: "GET"
  5. The "JWT Authentication", "URL Parameters" and "Body" sections don't need to be modified Create Route

Building the Route Logic in the Flow Editor

The Flow Editor is where we define what happens when our route is called. We'll build a flow that:

  1. Fetches the current counter value
  2. Increments it by 1
  3. Updates the stored value
  4. Returns the new value

Follow these steps:

  1. Add a FETCH block:

    • Drag a FETCH block onto the canvas and connect the START node to it
    • Fill in the following details:
      • Local Name: "_allCounts"
      • Reference Collection: "count"

    Fetch Block

  2. Add a PROPERTY block:

    • Drag a PROPERTY block onto the canvas and connect the FETCH block to it
    • Fill in the following details:
      • Local Name: "_currentCount"
      • Property Apply: "GET_INDEX"
      • Additional: "0"
    • As for the data section, fill in the following details:
      • Reference: Check this box
      • Type: "Array"
      • Data: "_allCounts"

    Property Block

  3. Add another PROPERTY block:

    • Drag another PROPERTY block onto the canvas and connect the previous PROPERTY block to it
    • Fill in the following details:
      • Local Name: "currentCountValue"
      • Property Apply: "GET_PROPERTY"
      • Additional: "value"
    • As for the data section, fill in the following details:
      • Reference: Check this box
      • Type: "Other"
      • Data: "_currentCount"

    Property Block

  4. Add an ASSIGNMENT block:

    • Drag an ASSIGNMENT block onto the canvas and connect the PROPERTY block to it
    • Fill in the following details:
      • Local Name: "updatedCount"
    • Add an "operation" submodule with 2 operands, and fill in the following details:
      • First Operand:
        • Reference: Check this box
        • Type: "Integer"
        • Data: "currentCountValue"
      • Second Operand:
        • Reference: Leave unchecked
        • Type: "Integer"
        • Data: "1"
    • Operation Type: "Addition"

    Assignment Block

  5. Add an UPDATE block:

    • Drag an UPDATE block onto the canvas and connect the ASSIGNMENT block to it
    • Fill in the following details:
      • Reference Collection: "count"
      • Reference Property: "value"
    • As for the set section, fill in the following details:
      • Reference: Check this box
      • Type: "Integer"
      • Data: "updatedCount"
    • Add an "update target" submodule with 1 operand, and fill in the following details:
      • Field: "id"
      • Operand:
        • Reference: Leave unchecked
        • Type: "Integer"
        • Data: "0"
        • Condition Type: "Equal To"
    • Set: Check this box
    • Save: Check this box

    Update Block

  6. Add a RETURN block:

    • Drag a RETURN block onto the canvas and connect the UPDATE block to it
    • Add an "object pair" submodule
    • Fill in the following details:
      • id: "count"
      • data:
        • Reference: Check this box
        • Type: "Integer"
        • Data: "updatedCount"

    Return Block

  7. Ensure that your Flow Editor looks like the following: Flow Editor

  8. Click "Create" to save your route

Route Page

6. Testing via Playground

Now let's test our counter API:

  1. Navigate to "Playground" in the top navigation bar
  2. Select your project Playground Page
  3. Click on the "GET_COUNTER" route Playground Project Page
  4. Click "Send" to make a request to your API
  5. You should see a response like:
    {
      "count": 1
    }
    
  6. Click "Send" again and you should see the counter increment:
    {
      "count": 2
    }
    

Playground Request Page

Congratulations!

You've successfully built a simple counter API using Kinesis API! Here's what you've accomplished:

  • Created a project to organize your API
  • Set up a collection to store data
  • Defined some structures (fields) for your counter
  • Created a data object with an initial value
  • Built a route that increments the counter
  • Tested your API and verified it works

Next Steps

Now that you understand the basics, here are some ways to extend this project:

  1. Add a reset route: Create a new route that resets the counter to zero
  2. Add custom increment: Modify the route to accept a parameter that specifies how much to increment by
  3. Add multiple counters: Create multiple data objects and update your route to increment a specific counter
  4. Add authentication: Require a token to increment the counter

Continuous Improvement

Note: Kinesis API is continuously evolving based on user feedback. As users test and provide suggestions, the platform will become simpler, more intuitive, and easier to use. This tutorial will be updated regularly to reflect improvements in the user experience and new features.

We value your feedback! If you have suggestions for improving this tutorial or the Kinesis API platform, please reach out through our contact page.