{"id":13578835,"url":"https://github.com/rxi/sandbird","last_synced_at":"2025-05-06T08:31:12.654Z","repository":{"id":147019508,"uuid":"44445841","full_name":"rxi/sandbird","owner":"rxi","description":"A tiny embeddable HTTP server written in C89","archived":false,"fork":false,"pushed_at":"2019-10-27T11:12:58.000Z","size":22,"stargazers_count":182,"open_issues_count":4,"forks_count":25,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-30T18:05:48.691Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rxi.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}},"created_at":"2015-10-17T16:47:33.000Z","updated_at":"2025-04-16T08:24:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"c69814d3-f203-46f4-b2c4-f827511355c6","html_url":"https://github.com/rxi/sandbird","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rxi%2Fsandbird","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rxi%2Fsandbird/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rxi%2Fsandbird/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rxi%2Fsandbird/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rxi","download_url":"https://codeload.github.com/rxi/sandbird/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252648575,"owners_count":21782405,"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":[],"created_at":"2024-08-01T15:01:34.200Z","updated_at":"2025-05-06T08:31:12.400Z","avatar_url":"https://github.com/rxi.png","language":"C","funding_links":[],"categories":["C","Protocols"],"sub_categories":["Web Server"],"readme":"# Sandbird\nA tiny (~800sloc) embeddable HTTP server written in C89, compatible with Linux,\nOSX and Windows.\n\n\n## Getting started\nSandbird consists of two files: [sandbird.c](src/sandbird.c?raw=1) and\n[sandbird.h](src/sandbird.h?raw=1). Both of these files should be dropped into\nan existing project and compiled along with it. Sandbird works asynchronously\nand does not use threads, an event handler is invoked when an event -- such as\na request -- occurs.\n```c\nstatic int event_handler(sb_Event *e) {\n  if (e-\u003etype == SB_EV_REQUEST) {\n    sb_send_status(e-\u003estream, 200, \"OK\");\n    sb_send_header(e-\u003estream, \"Content-Type\", \"text/plain\");\n    sb_writef(e-\u003estream, \"Hello world\");\n  }\n  return SB_RES_OK;\n}\n```\n\nThe server is initialised by setting up a `sb_Options` struct and passing a\npointer to it to `sb_new_server()`. At a minimum the `port` and `handler`\nfields of the `sb_Options` struct should be set.\n```c\nsb_Server *srv;\nsb_Options opt;\n\nmemset(\u0026opt, 0, sizeof(opt));\nopt.port = \"8000\";\nopt.handler = event_handler;\n\nsrv = sb_new_server(\u0026opt);\n```\n\nIf `sb_new_server()` encounters an error, `NULL` is returned -- in this case it\nis most likely the socket could not be bound. A non-NULL return value means the\nserver started successfully and is listening for connections.\n\nThe poll function must be called on the server object regularly so that it can\nhandle new and existing connections. The poll function accepts a timeout value\nin milliseconds -- if this is set to `0` then the function will not block.\n```c\nfor (;;) {\n  sb_poll_server(srv, 1000);\n}\n```\n\nWhen we are done with the server the `sb_close_server()` function can be called\non it. This will close the server's listening socket and free any resources\nwhich were being used.\n```c\nsb_close_server(srv);\n```\n\nSome simple example programs can be found in the [example/](example/)\ndirectory.\n\n\n## License\nThis library is free software; you can redistribute it and/or modify it under\nthe terms of the MIT license. See [LICENSE](LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frxi%2Fsandbird","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frxi%2Fsandbird","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frxi%2Fsandbird/lists"}