GithubHelp home page GithubHelp logo

lau1944 / snowow Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 1.0 238 KB

A low code web service build on top of Spring

License: Apache License 2.0

Java 99.03% Shell 0.97%
api backend spring low-code springboot webserver framework webservice java

snowow's Introduction

Snowow

A low code service engine built on top of Spring

J

Introduction

Snowow is a low code service engine only requires developers to write JSON files to run a web service. Snowow is built on top of Spring boot, with the great advantages of MVC framework. Developer does not need to worry about the JAVA code, service is all depended on JSON files.

By writing JSON files in the resource folder, snowow would generate Spring code based on the JSON you wrote. Snowow definitely would speed up the process of backend development, improve code reusability and reduce error.

Guide

Installation

Clone the project into local directory

    git clone https://github.com/lau1944/snowow.git

Open your shell on the project directory and run

    source .snowow.sh

Then you can use Snowow command to simplify the process

Initialize the project

    snowow init

After that, you will see a snow_app folder in your resource folder in the application module.

api : This folder is for storing API related files. Files suffix with .http.json is the JSON file for HTTP method.

model : Declaring Data model in the service

configuration.json: Configuration json file for Spring configuration.

Configuration

Currently, configuration.json supports these following properties.

debug: (Boolean) Set the application mode for service, default to true

appName: (String) Application name

port: (String) Server socket port, default to 80

profiles: (String) Server profiles, will generate application-dev.properties file, default to dev

env: (Json) additional environment configuration, can be received using $(env)your_env_name

Here is the sample configuration file

{
  "debug": true,
  "appName": "SnowApp",
  "profiles": "dev",
  "port": 8080,
  "env": {
    "api_key": "123456"
  }
}

Model

Declare data model in JSON format.

name: (String) data model name

fields: (Array) array of fields object.

Sample model files of User.json

{
  "name": "User",
  "fields": [
    {
      "name": "name",
      "type": "String",
      "nullable": false
    },
    {
      "name": "age",
      "type": "int",
      "nullable": true
    }
  ]
}

HTTP

Declare API in JSON files

name: (String) API name

version: (String) API version

path: (String) API global path

paths: (Array) array of Path object

Path object

name: (String) method name

path: (String) method path

API method type: (String) API method, ex, GET, POST, PUT...

action: (JSON) service action (will discuss later)

response object:

status: (Int) response status, default 200

type: (String) response type, default application.json

data object:

type: Data object type

value: (Json) your response data if you want to specify response data, default null

Here is the sample user.http.json

{
  "name": "User",
  "version": 1.0,
  "path": "/user",
  "paths": [
    {
      "name": "getUserInfo",
      "path": "/info",
      "method": "GET",
      "action": "",
      "response": {
        "status": 200,
        "type": "application/json",
        "data": {
          "type": "User",
          "value": {
            "name": "@{params.name}",
            "age": 22,
            "school": [
              {
                "name": "@{params.school}",
                "age": 4
              },
              {
                "name": "Cornell University",
                "age": 2
              }
            ]
          }
        }
      }
    }
  ]
}

Data form

Each .http.json file would generate one controller class.

Inside the file, every path object inside the paths array, we would generate one HTTP method, similar to writing the controller method with @GetMapping on it.

Inside the method, we can define headers and params, which corresponding to our http RequestHeaders and RequestParams

If you want to receive these value inside the scope of this method, here is format to retrieve the data.

@{params.your_params_field} @{headers.your_headers_field}

Internally, params and headers will be converted to Map object, calling

@{params.xx} is basically params.get("xx") in Java.

Similar, @{headers.xx} = headers.get("xx")

Here is the sample response data in JSON

{
  "data": {
    "type": "Car",
    "value": {
      "age": "@{params.age}",
      "name": "@{headers.name}"
    }
  }
}

In the above data, our response will be return the value with key age inside RequestParams, the value with key name inside RequestHeaders.

You can also get your configuration element with this syntax.

{
  "value": {
    "key": "@{configs.env.key}"
  }
}

It would get the property key in your env object inside your configuration file.

Remember to make sure your JSON reference is correct, if you call @{config.key}, but key is not in the config object, you will get a NullPointer exception at compile time.

Action

One of the cool features in Snowow is you can play with action, it's what make Snowow powerful.

Action should be and only be defined in the path.

Action type Funtionalities
redirect Call the third party API
query Query from database
insert Insert data to database
delete Delete data from database

Currently, only support redirect action.

Redirect

Sample redirect syntax

"paths": [
    {
        "name": "getBread",
        "path": "/info",
        "method": "GET",
        "action": {
            "type": "redirect",
            "url": "https://api.thecatapi.com/v1/images/search",
            "method": "GET",
            "headers": {
              "x-api-key": "@{configs.env.api_key}"
            },
            "params": {
                "breed_id": "beng"
              }
        },
        "response": {
            "status": 200,
            "type": "application/json",
            "data": {}
        }
    }
]
  • After you define action type with redirect, response data will be ignored, the server will return the response of the third party API call.
  • You can use the @{params.xx} @{headers.xx} data form inside headers and params

Run

    snowow build

It would compile the JAVA code and start the Tomcat server.

Future

Snowow is still in the early step of construction, feel free if you are eager to contribute.

snowow's People

Contributors

lau1944 avatar

Stargazers

Andrew NS Yeow avatar  avatar albert liu avatar  avatar Kota avatar  avatar

Watchers

Kurukshetran avatar  avatar

Forkers

ajunlonglive

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.