ποΈ
Posts tagged with :lower_left_fountain_pen:
define middleware { test, logger } from "./api" define guards { authed } from "./api" define handlers { getAllTodos, postTodos } from "./api" global | middleware logger fragment getTodosFragment(level) | guard authed(level) | middleware test route "/todos" { | middleware test get { | expand getTodosFragment("user") getAll } post { | expand getTodosFragment("admin") postTodos } } π οΈ The Idyllic language reverses the conventional paradigm that surrounds Node REST APIs: usually, you have to write your functions _for a framework_. With Idyllic, you can assemble your API completely independently of your functions themselvesβnow, an API is simply a wrapper over regular old Typescript functions! The language itself comes with a pretty big suite of features (you can read more about them at the Github page): β’ Static typing with Typescript & definition types β’ Parameterized, first-class macro support with Fragments β’ Data pipelines with Sequences β’ First-class support for Middleware and Guards β’ Query parameter capturing β’ Request type definitions πΈοΈ The repository also comes with a minimal HTTP server that takes in a compiled Idyll and starts up a fully-functioning API from it: import { IdyllicCompiler } from "@idyllic/compiler"; import { IdyllicServer } from "@idyllic/server"; (async () => { // The fromFile static method reads the file into a string for us const compiler = await IdyllicCompiler.fromFile("ast.idl") // The compile method executes all 5 stages of compilation automatically. const compiled = await compiler.compile() // The server constructor takes in a compiled Idyllic object. const server = new IdyllicServer(compiled) // The start function takes in a port number (defaults to 3000) and a function to be executed on start. server.start(3000, () => { console.log("Idyllic server has started!") }) })()π¨ This server implementationβs pretty fast, too: in most cases, it comes close to (and in some cases, beats) Express! Itβs derived directly from nodeβs built-in
http
module.
Idyllicβs been a project that Iβve dreamt of making for quite a while now, and Iβm super happy with how it turned out! Iβve included a little walkthrough of an Idyllic project down below :) I canβt wait to see what youβll build with it!
Special thanks to @JackyZhao @matthewgleich @safin.singh for being awesome along the way β¨graphql-code-generator
you need to do a lot of null checks. This is for a good reason but I'd rather have that edge case to deal with than have to write a bunch of checks, so I wrote a CLI tool to get the GraphQL schema, modify it so that the types match the data from the Contentful management API, and write it to a file that the codegen tool can use