{"id":20273459,"url":"https://github.com/ekmartin/sprocket","last_synced_at":"2026-03-08T15:31:33.469Z","repository":{"id":75307803,"uuid":"88874433","full_name":"ekmartin/sprocket","owner":"ekmartin","description":"A developer friendly mit-scheme web framework","archived":false,"fork":false,"pushed_at":"2017-05-09T23:44:10.000Z","size":11099,"stargazers_count":7,"open_issues_count":8,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-14T06:12:58.232Z","etag":null,"topics":["api","framework","mit-scheme","web"],"latest_commit_sha":null,"homepage":"","language":"Scheme","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ekmartin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-20T14:23:23.000Z","updated_at":"2023-05-25T20:48:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"8a325f3d-d666-4546-9ef7-55ee43849c29","html_url":"https://github.com/ekmartin/sprocket","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekmartin%2Fsprocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekmartin%2Fsprocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekmartin%2Fsprocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekmartin%2Fsprocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ekmartin","download_url":"https://codeload.github.com/ekmartin/sprocket/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241763755,"owners_count":20016162,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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","framework","mit-scheme","web"],"created_at":"2024-11-14T12:49:08.277Z","updated_at":"2026-03-08T15:31:28.449Z","avatar_url":"https://github.com/ekmartin.png","language":"Scheme","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sprocket\nSprocket is a developer friendly web framework for MIT Scheme, built during [6.945: Adventures in Advanced Symbolic Programming](https://groups.csail.mit.edu/mac/users/gjs/6.945/).\n\n## Installation\nBecause Sprocket relies on `httpio`, it requires at least mit-scheme v9.\n\n```bash\n$ git clone https://github.com/ekmartin/sprocket.git\n```\n\nThen in your Scheme project you can do:\n\n```scheme\n(cd \"sprocket\")\n(load \"server.scm\")\n```\n\n## Usage\n```scheme\n;;; First create a new server instance:\n(define server (create-server))\n\n;;; Attach a handler:\n(get server\n     (lambda (req params) '(200 () \"Hello World!\"))\n     '(\"hello-world\"))\n\n;;; And finally, start the server on port 3000:\n(listen server 3000)\n```\n\n## API\n### Core\nSprocket lets you build applications as a set of middleware that\nturns a request into a response. The basic\nbuilding block for creating new middleware is `add-handler`:\n\n**add-handler** *server* *handler* *[path]* *[method]*\n\nExample:\n```scheme\n(add-handler server\n  (lambda (req params)\n    (printf \"-\u003e request: ~A\" req)))\n```\n\nSprocket also provides a set of helper procedures that makes\nit easier to define new handlers:\n\n**get** *server* *handler* *[path]*\n\n**post** *server* *handler* *[path]*\n\n**put** *server* *handler* *[path]*\n\n**delete** *server* *handler* *[path]*\n\nExample:\n```scheme\n(post server\n  (lambda (req params) '(200 () \"Let's add a cat!\"))\n  '(\"cats\"))\n```\n\nIn a similar vein, Sprocket also lets you define\nmiddleware that are only called in case of errors:\n\n**add-error-handler** *server* *handler* *[path]* *[method]*\n\nExample:\n```scheme\n(add-error-handler\n  server\n  (lambda (req params err)\n    (printf \"-\u003e error: ~A - in request: ~A\" err req)))\n```\nSimilar to express's bodyParser.json(), Sprocket allows you to\ntake in json data and parse it into a Scheme data structure,\nmaking use of `json-decode` from https://github.com/joeltg/json.scm.\nYou can make use of this functionality by calling:\n\n**add-handler** *server* *json-body-parser*\n\nExample:\n```scheme\n(post server\n      (lambda (req)\n        (let ((body (http-request-body req)))\n          (printf \"body: ~A\" body)\n          (string-append\n           \"First value: \"\n           (cdar (vector-ref body 0)))))\n      '(\"insert\"))\n```\n\n### Utilities\n#### Static Files\nNot all requests require handlers - sometimes you just\nwant to return a file. Sprocket provides a `serve-static`\nhelper for this:\n\n**serve-static** *path*\n\nExample:\n\n```scheme\n(get server (serve-static \"public\") '(\"static\"))\n```\n\nThis would for example cause Sprocket to respond to\na `/static/file.txt` request with the contents of\n`./public/file.txt`. In the case where Sprocket\nfails to read file at `path`, it turns over control\nto the next middleware, and logs the error.\n\n#### Redirects\n`redirect` returns a response that redirects the client\nto the given location.\n\n**redirect** *location* *[status = 302]*\n\nExample:\n```scheme\n(get server\n  (lambda (req params)\n    (redirect \"http://localhost:3000/hello-world\"))\n  '(\"redirect\"))\n```\n\n#### Routing Parameters\nThe path argument to `add-handler` is a list where each\nelement matches a forward slash separated segment of a URL.\nThis can either be a string, or one of the symbols `number-arg`\nand `string-arg`. The last two matches arbitrary values of their\nrespective types, and passes a list of the matched parameters\nto the request handler.\n\nExamples:\n```scheme\n(get server\n     (lambda (req params)\n       `(200 ()\n             ,(string-append\n              \"We're buying cat number \"\n              (number-\u003estring (car params)))))\n     '(\"cats\" number-arg \"buy\"))\n\n(get server\n     (lambda (req params)\n       `(200 ()\n             ,(string-append\n              \"We're buying the dog named \"\n              (car params))))\n     '(\"dogs\" string-arg \"buy\"))\n```\n\n#### JSON Parsing\n`json-body-parser` takes in the existing request body as\njson, converts it into a Scheme data structure, and\nupdates the request body with the new body.\n\nUsage:\n```scheme\n(add-handler server (json-body-parser))\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fekmartin%2Fsprocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fekmartin%2Fsprocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fekmartin%2Fsprocket/lists"}