Coder Social home page Coder Social logo

frankiegu / apigo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from elaugier/apigo

0.0 1.0 0.0 14.36 MB

ApiGo is an API engine which allow to build quickly a REST API without development. If you have already some scripts written in Powershell, Python, ... and you need to expose these through an web API, ApiGo may be your solution.

Home Page: https://apigo.egen.guru/

License: GNU General Public License v3.0

Go 99.86% Batchfile 0.14%

apigo's Introduction


IMPORTANT

ApiGo is currently in development. For some private reasons, i can't work hard on this project. I hope have more time in several months. Sorry for that.


Table of Contents

  1. What is ApiGo?
  2. Implementation
  3. Installation
  4. Usage
  5. Security
  6. API
  7. Contributing
  8. License

What is ApiGo?

ApiGo is an API engine which allow to build quickly a REST API without development. If you have already some scripts written in Powershell, Python, ... and you need to expose these through an web API, ApiGo may be your solution.

Overview

Script Languages Compliance

Implementation

Components

There are some components in ApiGo:

  • an API Engine: apigo-engine
  • a Worker: apigo-worker
  • a Message Broker: Apache Kafka, RabbitMQ, ZeroMQ*
  • a Database: Postgresql, MySQL, etc.

And as soon as possible:

  • an Authentication service
  • an Authorization service (per App Domain)

Dependencies

Installation

Before install the components, you must build the project.

Build and publish ApiGo

Open a command line in ApiGo git root folder and type the following command :


Linux : TBD

Windows : build.cmd

Back to top

ApiGo installation

TBD

Back to top

Setup ApiGo as windows service

To setup coreApi as windows service, we recommand to use NSSM

Follow the instructions written on the following url https://nssm.cc/usage

Back to top

Usage

Engine Configuration

All configurations are stored in the folder config.

At root, there is a file default.json. This is the main configuration.

{
  "AccountingDatabase": {
    "AdminDatabase": "",
    "ConnectionString": "",
    "Driver": "postgres"
  },
  "Bindings": "0.0.0.0:1203",
  "CertPath": "",
  "CertPwd": "",
  "JobsDatabase": {
    "AdminDatabase": "",
    "ConnectionString": "",
    "Driver": "postgres"
  },
  "KafkaProducer": {
    "BootstrapServers": "localhost:9092"
  },
  "MaxConcurrentConnections": "0",
  "MaxConcurrentUpgradeConnections": "0",
  "MaxRequestBodySize": "338657280",
  "RoutesConfigPath": "config/routes",
  "Secure": "false"
}

For each route you have to create two files. First with .conf.json like as following for a Powershell Cmdlet:

{
  "Name": "Route1",
  "Cmd": {
    "Name": "Command1",
    "Type": "Powershell",
    "PSModule": "PSModule",
    "Params": [
      {
        "Name": "Argument1",
        "Type": "String",
        "Mandatory": "True",
        "In": "body"
      }
    ]
  },
  "Route": "/route1",
  "Method": "POST",
  "JobType": "synchronous",
  "Topic": "topic1",
  "Timeout": "15000",
  "AddRequestIdParam": "True"
}
  • Type : must be equal to "Powershell" or "Python" or "Perl" or "CommandLine"
  • PSModule : only for Powershell type, you must specify the module where the cmdlet is defined
  • Method : must be equal to "GET" or "POST" or "PUT" or "PATCH" or "DELETE"
  • JobType : must be equal to "synchronous" or "asynchronous"
  • Timeout : for synchronous job, the timeout is the duration until CoreApi considers that the job won't be completed
  • Topic : this is the topic where all jobs for this API entry were sent

Same example for Python script:

{
  "Name": "Route2",
  "Cmd": {
    "Name": "pyCommand1",
    "Type": "Python",
    "PyVenv": "venv1",
    "Params": [
      {
        "Name": "Argument1",
        "Type": "String",
        "Mandatory": "True",
        "In": "body"
      }
    ]
  },
  "Route": "/route2",
  "Method": "POST",
  "JobType": "synchronous",
  "Topic": "topic1",
  "Timeout": "15000",
  "AddRequestIdParam": "True"
}

For Python script, you must define a new attribute "PyEnv" to allow the worker activate the good virtual environment

Back to top

Worker Configuration

All configurations are stored in the folder config.

At root, there is a file default.json. This is the main configuration.

{
  "AccountingDatabase": {
    "AdminDatabase": "",
    "ConnectionString": "",
    "Driver": "postgres"
  },
  "JobsDatabase": {
    "AdminDatabase": "",
    "ConnectionString": "",
    "Driver": "postgres"
  },
  "KafkaConsumer": {
    "BootstrapServers": "",
    "Debug": "",
    "GroupId": "winworkers"
  },
  "ScriptsPath": "config\\scripts",
  "WorkerTopic": "winworkersTopic",
  "OnMessageTimeout": "10000",
  "MaxConcurrentJobs":"0",
  "PoolWaitingTime","100"
}

Back to top

Worker scripts installation

Overview

the ApiGo worker can use any command, you can launch from the OS shell. But you have to know how worker returns the result to the engine.

The engine return result as 'application/json' and the standard response have the following structure:

{
	"sts":"",
	"hco":"",
	"msg":"",
	"dbg":"",
	"dta":""
}
  • sts : can contains these following values : "success", "failed"
  • hco : contains the http code status
  • msg : contains any useful message if needed
  • dbg : contains debug informations if needed
  • dta : contains string or any valid JSON structure returned by the command executed by the worker

Back to top

Powershell CmdLets and Modules

To use Powershell with ApiGo, you must use Powershell Module (.psm1), not directly a script (.ps1). The main interest of the module is to limit the number of scripts to deploy on the workers by grouping the cmdlets in a single module file.

The following code is an minimal example of Powershell module.

# ApiGo (https://github.com/elaugier/ApiGo)
# -----------------------------------------
# script sample for Powershell

function HelloWorld {
    param (
    )
    @{ "message" = "Hello World!" } | ConvertTo-Json
}

Export-ModuleMember -Function HelloWorld

To make a PS Module available for ApiGo, you just have to copy your file under the folder psmodules in the scripts directory (watch the worker configuration file to know it)

Back to top

Python scripts and virtual environments

To use Python scripts, you need to configure at least one virtual environment.

  1. Open a shell under the folder PyEnvs in the scripts directory (watch the worker configuration file to know it)
  2. Create a virtual environment with the following command :
        python -m venv [VirtualEnvName]
  1. To make a Python script available for ApiGo, you just have to copy your file under the folder python-scripts in the scripts directory

The following code is an minimal example of Python script.

# ApiGo (https://github.com/elaugier/ApiGo)
# -----------------------------------------
# script sample for Python

import json

t = {'message':'Hello World'}
print(json.dumps(t))

Back to top

Perl

To make a Perl script available for ApiGo, you just have to copy your file under the folder perl-scripts in the scripts directory (watch the worker configuration file to know it)

The following code is an minimal example of Perl script.

# ApiGo (https://github.com/elaugier/ApiGo)
# -----------------------------------------
# script sample for Perl

use JSON;

my %msg = ('message' => 'Hello World!');
my $json = encode_json \%msg;
print $json

Back to top

Ruby

To make a Ruby script available for ApiGo, you just have to copy your file under the folder ruby-scripts in the scripts directory (watch the worker configuration file to know it)

The following code is an minimal example of Ruby script.

# ApiGo (https://github.com/elaugier/ApiGo)
# -----------------------------------------
# script sample for Ruby

require 'json/ext'

t = {:message => "Hello World!"}
puts t.to_json

Back to top

PHP

To make a PHP script available for ApiGo, you just have to copy your file under the folder php-scripts in the scripts directory (watch the worker configuration file to know it)

The following code is an minimal example of PHP script.

<?php
/**
 * ApiGo (https://github.com/elaugier/ApiGo)
 * -----------------------------------------
 * 
 * script sample for PHP
 */
$t = [
    "message" => "Hello World!"
];

echo json_encode($t);

Back to top

Security

ApiGo only supports the Key API for the moment. It will evolve in the future.

API

Back to top

Contributing

Open an issue first to discuss potential changes/additions.

Back to top

License

GNU General Public License v3.0

Egen Guru logo

contact : [email protected]

Back to top

apigo's People

Contributors

elaugier avatar

Watchers

 avatar

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.