Git Product home page Git Product logo

api-codegen's Introduction

Hasura API Code Generator

npm module to generate code for Hasura APIs in different languages/frameworks

Languages Covered

  • Python
  • JavaScript
  • Node.js
  • Swift
  • Java

Usage

npm install api-codegen

import {CodeGenerator} from 'api-codegen';

const moduleName = 'Node Fetch'; // replace with module of choice
let generator = new CodeGenerator(moduleName);
let generatedCode;

try {
  generatedCode = generator.generate({
    url: '', // replace with request URL
    method: '', // replace with request Method (GET, POST, PUT, DELETE)
    headers: {}, // add header key-value pairs
    param: {}, // add request body
    type: '' // specify 'file' for generating filestore API or leave it empty
  });
} catch (e) {
  generatedCode = e.message;
}
console.log(generatedCode); // Generated Code Snippet

If you want to add support for a language or a library within a language, follow the steps below.

Getting started

  1. Build your library
  • Run yarn install (recommended) or npm install to get the project's dependencies
  • Run yarn build or npm run build to produce minified version of your library.
  1. Development mode
  • Having all the dependencies installed run yarn dev or npm run dev. This command will generate an non-minified version of your library and will run a watcher so you get the compilation on file change.

Scripts

  • yarn build or npm run build - produces production version of your library under the lib folder
  • yarn dev or npm run dev - produces development version of your library and runs a watcher
  • yarn test or npm run test - well ... it runs the tests :)
  • yarn test:watch or npm run test:watch - same as above but in a watch mode

Testing

  • Once the code generator for the new module has been written, it can be tested by: sh test.sh '<MODULE_NAME>' <PATH_TO_DOCKERFILE>

Here the

  • '<MODULE_NAME>' comes from the CodeGenerator.TYPES
  • '<PATH_TO_DOCKERFILE>' should give the path of the Dockerfile written for this new module execution.

This shell script takes the module name, generates the Code Snippet based on the written function and saves the snippet file named as test in the given path. A docker image is built with the test file added. Docker container is run with the built image and is expected to only output the response of the sample http request.

Contributing

We love community contributions. If you would like to contribute, raise a PR after testing your code generation logic.

api-codegen's People

Contributors

praveenweb avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

forkkit 5l1v3r1

api-codegen's Issues

Swift Codegen issue

  • change var to let for request param
  • Alamofire.request method param chronology change
  • Alamofire.request method params missing commas

Add comment with install instructions for dependencies

Javascript Node for example should have the following comment on the first line
// run npm install --save node-fetch in the same directory as your package.json file.

Explore other languages and their appropriate dependency method.
Atleast link to the frameworks github page or something where a user can find installation instructions.

Grouping Languages / Frameworks

Currently the list of frameworks are individually listed. For example: JavaScript (jQuery), JavaScript (Node Fetch).

Grouping them according to each language would be better so that more and more libraries can be integrated.

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.