Giter Site home page Giter Site logo

linecode / zetro Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jnsquire/zetro

0.0 1.0 0.0 76 KB

Generate typed and extremely efficient APIs from a schema file

License: GNU General Public License v3.0

JavaScript 0.47% TypeScript 2.36% Shell 0.42% Rust 96.75%

zetro's Introduction

Zetro

Generate typed and extremely efficient APIs from a schema file. Effectively turning an API response like this:

// 695 bytes: key-value pair
{"rooms":[{"id":0,"messages":[{"author":{"username":"hal42"},"date":1639903136,"id":192,"text":"cats are fun!"},{"author":{"username":"droopydifferential"},"date":1639898582,"id":23489,"text":"perhaps, but have you tried solving differential equations?"}],"name":"Furry cats","status":0},{"id":1,"messages":[{"author":{"username":"mitoch0ndria"},"date":1639904622,"id":3489,"text":"...so I told them to watch 3b1b..."},{"author":{"username":"droopydifferential"},"date":1639907197,"id":1290,"text":"that is indeed quite entertaining to hear."},{"author":{"username":"mitoch0ndria"},"date":1639907197,"id":2390,"text":"[mitoch0ndria left the room]"}],"name":"Differential calculus","status":0}]}

into this:

// 468 bytes: untagged array representation
[[["YiGepyIChwIjKAW1XFFbSD-DH-4",[[[0,[[["hal42"],1639903351,192,"cats are fun!"],[["droopydifferential"],1639898797,23489,"perhaps, but have you tried solving differential equations?"]],"Furry cats",0],[1,[[["mitoch0ndria"],1639904837,3489,"...so I told them to watch 3b1b..."],[["droopydifferential"],1639907412,1290,"that is indeed quite entertaining to hear."],[["mitoch0ndria"],1639907412,2390,"[mitoch0ndria left the room]"]],"Differential calculus",0]]]]],null]

⚠️ Warning ⚠️

Zetro currently generates only server code for Warp (Rust) and client code for TypeScript. PRs for other languages are welcome!

Getting Started

You need Cargo v1.56.0 or later to build Zetro. You can also use the binary releases

export REPO_FOLDER="zetro"

# Acquire the code
$ git clone https://github.com/muscache/zetro --depth 1 $REPO_FOLDER

# Build the tool
$ cd $REPO_FOLDER/zetro
$ cargo build

# Add zetro to PATH (recommended)
$ mv target/debug/zetro ~/.local/bin # Or move to /usr/local/bin

# Verify Zetro is installed
$ zetro # Should get 'Missing option --schema'

# Ready to run the example!

Running the example

Ensure you have installed Zetro correctly before proceeding.

$ cd $REPO_FOLDER/example

# Generate Rust and TypeScript code
./generate_code.sh

# Transpile + minify the client code
cd client
npm install
npm run build

# Start the API server
cd ../server
cargo run

# Visit http://localhost:8090 in your browser

Why?

This tool solves multiple problems:

  • Typed APIs: Ensures client and server payloads are always the type and shape you define.
  • Efficiency: Tiny payloads. Only transfer raw data, not keys.
  • Obfuscation: Not a primary goal, but Zetro does make it harder for third parties to reverse engineer or use your APIs.

Of course, GZipping already minifies API responses when using "normal" JSON, but Zetro takes it one step further by also reducing allocations (ie., allocation of keys in the object) when unpacking the response.

zetro's People

Contributors

muscache 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.