{"id":45495260,"url":"https://github.com/hastalavistababy/sonic-api-gateway","last_synced_at":"2026-02-22T17:35:46.977Z","repository":{"id":37483134,"uuid":"305193047","full_name":"hastalavistababy/sonic-api-gateway","owner":"hastalavistababy","description":"Nodejs API Gateway","archived":false,"fork":false,"pushed_at":"2021-05-04T21:41:29.000Z","size":115,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-06T16:00:55.901Z","etag":null,"topics":["api","api-gateway","apigateway","caching","nodejs","nodejs-api-gateway","sonic","sonic-api-gateway"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hastalavistababy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-18T20:44:31.000Z","updated_at":"2025-05-19T20:22:45.000Z","dependencies_parsed_at":"2022-08-23T20:10:35.589Z","dependency_job_id":null,"html_url":"https://github.com/hastalavistababy/sonic-api-gateway","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hastalavistababy/sonic-api-gateway","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hastalavistababy%2Fsonic-api-gateway","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hastalavistababy%2Fsonic-api-gateway/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hastalavistababy%2Fsonic-api-gateway/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hastalavistababy%2Fsonic-api-gateway/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hastalavistababy","download_url":"https://codeload.github.com/hastalavistababy/sonic-api-gateway/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hastalavistababy%2Fsonic-api-gateway/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29720569,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-22T15:10:41.462Z","status":"ssl_error","status_checked_at":"2026-02-22T15:10:04.636Z","response_time":110,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","api-gateway","apigateway","caching","nodejs","nodejs-api-gateway","sonic","sonic-api-gateway"],"created_at":"2026-02-22T17:35:46.784Z","updated_at":"2026-02-22T17:35:46.937Z","avatar_url":"https://github.com/hastalavistababy.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sonic - Nodejs API GATEWAY \n\n![alt text](https://iili.io/3lSIiF.png \"Sonic api gateway\")\n\nSonic is a high-performance 100% open source, config based free API Gateway for Nodejs. All source code is available under the MIT License on GitHub.\n\nIts core functionality is to create an API that acts as an aggregator of many microservices into single endpoints.\n\n\n## Features\n  * A single API that exposes many.\n  * Merge the content and modify of several APIs into one.\n  * Device detection (mobile, desktop).\n  * HTTP Caching(Redis, memory).\n  * Unlimited endpoints and backends.\n  * Secure the transport.\n  * Error handling.\n  * URL patterns and variables\n  * Request body validation\n  * Use middlewares(Response, Request, Error, and your own).\n  * Simple JSON configuration.\n\n### Installing: \nThis is a [Node.js](https://nodejs.org/en/) module available through the [npm registry](https://www.npmjs.com/package/sonic-api-gateway).\n\nUsing npm:\n\n```bash\n$ npm install sonic-api-gateway --save\n```\nUsing yarn:\n\n```bash\n$ yarn add sonic-api-gateway\n```\n\n### Example: \nNow that we have installed the Sonic API gateway module. \n\nLet's create a Sonic project file.\n\n___app.js___\n\n```js\nconst Sonic = require('sonic-api-gateway').Sonic\n\nconst Config = {\n  port : 3014, // Server will run on port 3014 \n  routes: [\n    {\n        endpoint: '/posts/:id', // http://localhost:3014/posts/:id\n        method: 'get',\n        backend: [\n            {\n                target: 'https://jsonplaceholder.typicode.com/posts/{id}',\n                method: 'get',\n                response_key : \"posts\",\n            },\n            {\n                target: 'https://jsonplaceholder.typicode.com/posts',\n                method: 'get',\n                response_key : \"all_posts\",\n            },\n            // ...\n        ]\n    },\n    // ...\n  ]\n}\n\nnew Sonic(Config);\n```\n\nStart Sonic server:\n\n```js\n node app.js \n```\n\nMake a GET request (as we declare in config) with CURL:\n\n```curl -G http://localhost:3014/posts/1```\n\n\n## Configuration options:\n```js\n{\n    version: String, // Optional\n    logs: Boolean, // Optional\n    port : Number, // Optional, Default 3000\n    debug: Boolean, // Optional, Default true, for logging\n    middlewares: Array, //Optional global middlewares in the format: (req, res, next) =\u003e next(), Default []\n    cache: [ // Optional\n        {\n            driver: String, // Required, redis | memory\n            host: String, // Optional\n            port: Number // Optional\n        }\n        // ...\n    ],\n    routes: [\n        {\n            endpoint : String, // Required, ex: \"/posts\"\n            method : String, // Required, GET, POST, DELETE, PUT\n            cache: { // Optional,\n                driver: String, // Required, redis | memory,\n                ttl: Number, // Optional, 1 = 1 second\n            },\n            params : { // Optional\n                [key: String] : String\n            },\n            onResponse?(req: any, res: any, next: any, data: any, route: any): Function; // Optional\n            onRequest?(req: any, res: any, next: any): Function; // Optional\n            backend: [\n                {\n                    target: String, // Required, ex: \"https://jsonplaceholder.typicode.com/posts\"\n                    method: String, // Required, GET, POST, DELETE, PUT\n                    response_key: String, // Optional\n                    response_status : Number, // Optional\n                    onResponse?(req: any, res: any, next: any, data: any, route: any): Function, // Optional\n                    auth : Boolean, // Optional\n                    onError?(req, res, next, proxyRoute, error) : Function // Optional\n                    params : { // Optional\n                        [key: String] : String\n                    },\n                    body: {\n                        [key: string]: 'string' | 'files' | 'any' | 'number' | 'boolean' \n                    }, // Required if request method is POST, PUT. ex: body : {name : 'string'}\n                    body_method: String, // Default : rawdata. Possible: formdata, urlencoded, raw\n                    headers: Object // Optional, set request header\n                    childRoutes: Backend[] // Experimental\n                }\n            ]\n        }\n        // ...\n    ]\n}\n```\n\n# API\n---\n### Options: \n1. [```PORT``` - Sonic server port](#PORT)\n2. [```VERSION``` - Informing client about Sonic version](#version)\n3. [```DEBUG``` - Sonic debug mode](#debug)\n4. [```LOGS``` - Log incoming requests info](#logs)\n5. [```MIDDLEWARES``` - Middlewares](#middlewares)\n6. [```CACHE``` - Caching responses](#cache)\n7. [```ROUTES``` - API](#routes)\n8. [```ROUTES.ENDPOINT``` - API endpoint](#routes.endpoint)\n9. [```ROUTES.METHOD``` API method](#routes.method)\n10. [```ROUTES.onResponse``` - Handle response](#routes.onresponse)\n11. [```ROUTES.CACHE```](#routes.cache)\n12. [```ROUTES.BACKEND```](#routes.baackend)\n13. [```ROUTES.BACKEND.TARGET```](#routes.backend.target)\n14. [```ROUTES.BACKEND.METHOD```](#routes.backend.method)\n15. [```ROUTES.BACKEND.RESPONSE_KEY```](#routes.backend.response_key)\n16. [```ROUTES.BACKEND.RESPONSE_STATUS```](#routes.backend.response_status)\n17. [```ROUTES.BACKEND.ONRESPONSE```](#routes.backend.onresponse)\n18. [```ROUTES.BACKEND.AUTH```](#routes.backend.auth)\n19. [```ROUTES.BACKEND.BODY```](#routes.backend.body)\n20. [```ROUTES.BACKEND.BODY_METHOD```](#routes.backend.body_method)\n21. [```ROUTES.BACKEND.HEADERS```](#routes.backend.headers)\n22. [```ROUTES.BACKEND.CHILD_ROUTES```](#routes.backend.child_routes)\n\n### ```port``` - Creates Sonic server\n\nStart a server listening for connections. It will create simple http server with express.\n\n**Type:** *Number*\n**Default:** *3000*\n**Required:** *false*\n\n**Example:**\n```\nnew Sonic({\n    port : 3014\n    // ...\n})\n```\n\n``` curl -G http://localhost:3014 ```\n\n\u003e :warning: If address allready in use server will not start\n\n### ```version``` - Informing client for Sonic version with header\n\nSeting response header for every response wich sending from server to client.\n\n**Type:** *String*\n**Default:** *1.0*\n**Required:** *false*\n\n**Example:**\n```\nnew Sonic({\n    version: 2.0,\n    // ...\n})\n```\n\n### ```debug``` - Sonic debug mode\n\nDebug styled server actions in your node.js console. It will log incoming requests, server status, caching servers status, invalid config error \n\n**Type:** *Boolean*\n**Default:** *true*\n**Required:** *false*\n\n**Example:**\n```\nnew Sonic({\n    debug: true\n    // ...\n})\n```\n\n![alt text](https://iili.io/3GFYNa.png \"Sonic api gateway\")\n\n### ```logs``` - Logs incoming request into file\nSave request date and client ip into the file in root directory ***_log/{date)***\n\n**Type:** *Boolean*\n**Default:** *false*\n**Required:** *false*\n\n**Example:**\n```\nnew Sonic({\n    logs : true,\n    // ...\n})\n```\n\n### ```middlewares``` - Express Middlewares\nUse Express middlewares. \n\n**Type:** *Array:Function(req,res,next)*\n**Default:** *none*\n**Required:** *false*\n\n**Example:**\n```\nnew Sonic({\n    middlewares: [\n        (req: Request, res: Response, next: NextFunction) =\u003e {\n            console.log(req.method)\n            next() // Don't miss \n        },\n        morgan(),\n        // ...\n    ]\n    // ...\n})\n```\n\n### ```cache``` - Caching backend response\n\nWith caching option you can cache every response to a redis or disk memory. This caching technique applies to traffic between Sonic and your microservices endpoints.\n\n**Type:** *Array:Object ```(port?: Number, host?: String, driver: 'redis' || 'memory')```*\n**Default:** *none*\n**Required:** *false*\n**Possible cache drivers:** *redis | memory*\n\n**Example:**\n```\nnew Sonic({\n    cache : [\n        {\n            driver: 'redis',\n            host: '1231.1.2.3.4',\n            port: 12701\n        },\n        {\n            driver: 'memory',\n        }\n    ],\n    routes : [\n        {\n            endpoint: \"/v1/test\",\n            method: \"get\",\n            cache: {\n                driver: \"memory\",\n            },\n            backend: [\n                // ...\n            ]\n        },\n        {\n            endpoint: \"/v1/test/pets\",\n            method: \"get\",\n            cache: {\n                driver: \"redis\",\n            },\n            backend: [\n                // ...\n            ]\n        }\n    ]\n    // ...\n})\n```\n### ```routes``` - API routes\nAn array of endpoint objects offered by the gateway, all the associated backends and configurations.\n\n**Type:** *Array:Object*\n**Default:** *none*\n**Required:** *true*\n\n**Example:**\n```\nnew Sonic({\n    routes : [\n        {\n            endpoint: \"/v1/test\",\n            method: \"get\", \n            backend: [\n                // ...\n            ]\n        },\n        // ...\n    ]\n    // ...\n})\n```\n\n### ```routes.endpoint``` - Api endpoint name\nThe resource URL you want to expose\n\n**Type:** *String*\n**Default:** *none*\n**Required:** *true*\n**Note:** *Endpoints starts with \"/\"*\n\n**Example**\n```\nnew Sonic({\n    // ... \n    routes : {\n        endpoint : \"/v1/test-endpoint\"\n        // ... \n    }\n    // ... \n})\n```\n\n    curl http://localhost:3014/v1/test-endpoint\n\n### ```routes.method``` - Api request method\nRequest method, GET, POST, PUT or DELETE\n\n**Type:** *String*\n**Default:** *get*\n**Required:** *true*\n**Note:** *Possible : GET, POST, PUT, DELETE*\n\n\n**Example**\n```\nnew Sonic({\n    // ...\n    routes : {\n        endpoint : \"/v1/test-endpoint\",\n        method : \"get\"\n        // ...\n    }\n    // ...\n})\n```\n\n    curl http://localhost:1001/v1/test-endpoint\n\nDocumentation in progress.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhastalavistababy%2Fsonic-api-gateway","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhastalavistababy%2Fsonic-api-gateway","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhastalavistababy%2Fsonic-api-gateway/lists"}