{"id":1978,"url":"https://github.com/elliottminns/blackfire","last_synced_at":"2025-08-02T05:33:21.193Z","repository":{"id":45922856,"uuid":"51004037","full_name":"elliottminns/blackfire","owner":"elliottminns","description":"A minimal, fast and unopinionated web framework for Swift","archived":false,"fork":false,"pushed_at":"2021-11-23T14:31:38.000Z","size":614,"stargazers_count":904,"open_issues_count":4,"forks_count":39,"subscribers_count":34,"default_branch":"master","last_synced_at":"2024-08-02T08:08:38.075Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elliottminns.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-03T14:14:15.000Z","updated_at":"2024-07-18T19:51:26.000Z","dependencies_parsed_at":"2022-09-24T18:51:23.488Z","dependency_job_id":null,"html_url":"https://github.com/elliottminns/blackfire","commit_stats":null,"previous_names":["elliottminns/blackfish"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/elliottminns/blackfire","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elliottminns%2Fblackfire","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elliottminns%2Fblackfire/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elliottminns%2Fblackfire/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elliottminns%2Fblackfire/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elliottminns","download_url":"https://codeload.github.com/elliottminns/blackfire/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elliottminns%2Fblackfire/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268339405,"owners_count":24234544,"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","status":"online","status_checked_at":"2025-08-02T02:00:12.353Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-01-05T20:16:00.381Z","updated_at":"2025-08-02T05:33:20.884Z","avatar_url":"https://github.com/elliottminns.png","language":"Swift","funding_links":[],"categories":["Server","Swift"],"sub_categories":["Keychain","Other free courses"],"readme":"![Fire Image]\n(http://i.imgur.com/1qR6Nl4.png)\n\n# Blackfire\n###### An extremely fast Swift web framework\n![Swift Version](https://img.shields.io/badge/Swift-3.0-orange.svg)\n[![SwiftPM compatible](https://img.shields.io/badge/SwiftPM-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager)\n![License Apache](https://img.shields.io/badge/License-Apache-lightgrey.svg) \n![Plaforms](https://img.shields.io/badge/Platforms-Linux%20%7C%20macOS%20-blue.svg)\n\n\n## 🔥 Getting Started\n\nIf you're familiar with express.js then Blackfire will be known to you. The most simple example of how to use can be seen below:\n\n```swift\nmain.swift\n\nimport Blackfire\n\n// Create a nice new 🔥 app for us to play with.\nlet app = Flame()\n\n// Let's add a route to begin with.\napp.get(\"/\") { (req, res) in\n  res.send(text: \"Hello World\")\n}\n\napp.start(port: 3000) { result in\n  switch result {\n    case .success:\n      print(\"Server started on port 3000\")\n    case .failure(let error):\n      print(\"Server failed with error: \\(error)\")\n  }\n}\n```\n\n```\n$ curl localhost:3000 \nHello World%\n```\n\n## 🎁 Features\n\nBlackfire has all the standard features of a typical minimal Web Framework, let's take a look at some of these.\n\n### 🔱 Routing\n\nRouting, as seen in the above example, takes place by assigning a handler to a method in your App\n\n``` swift\napp.get(\"/\") { (req, res) in\n  res.send(text: \"I'm a GET request\")\n}\napp.post(\"/users\") { (req, res) in\n  res.send(text: \"I'm a POST request to /users\")\n}\napp.delete(\"/all/files\") { (req, res) in\n  res.send(text: \"I'm a DELETE request to /all/files ...wait\")\n}\napp.put(\"/em/up\") { (req, res) in\n  res.send(text: \"I'm a PUT request to /em/up Am I being robbed?\")\n}\n```\n\nThis can become tedious if you have a lot of `/users/\u003csomething\u003e` routes however, so we created the........\n\n### 🐒 Router\n###### Don't be scared that it's a monkey handling it, he had a pretty decent job interview on the whiteboard and seems to be doing ok.\n\nThe router object allows you to group routes together. For example\n\n```swift\nlet users = Router()\nusers.get(\"/\") { req, res in\n  res.send(text: \"Get me all the users\")\n}\nusers.post(\"/\") { req, res in\n  res.send(text: \"Creating a new user\")\n}\nusers.get(\"/favourites\") { req, res in\n  res.send(json: [\"food\": \"🍌\"])\n}\n\n// Let's use the router to match for /users\napp.use(\"/users\", users)\n\n```\n```\n$ curl localhost:3000/users\nGet me all the users%\n$ curl localhost:3000/users/favourites\n{\"food\":\"🍌\"}%\n```\n\nPowerful stuff. \n\n## 📫 Request\n\nThe request or `req` object contains a bunch of helpful information that your handler may want to use:\n\nThese include:\n\n* `request.params` A key value pair of `Strings` that are matched in the route\n* `request.body` The raw body of the recieved request, in the form of a `String`\n* `request.headers` A key value pair of `Strings` of the headers that appeared in the route\n* `request.method` The method of this request, formed from the `HTTPMethod` enum.\n* `request.path` The path of this request\n* `request.httpProtocol` The protocol for this request.\n\n## 📣 Response\n\nThe response or `res` object contains everything you need to return data back to the consumer\n\n* `res.send(text: String)` Send back a basic text response in the form of `Content-Type: text/plain`\n* `res.send(json: Any)` Send back some JSON, takes in a JSON parseable object. This method can fail if the object is not parseable\n* `res.send(status: Int)` Send back a HTTP status with no body\n* `res.send(html: String)` Send back some html with the header of `Content-Type: text/html`\n* `res.send(error: String)` Sends back an error, setting the status to `500`.\n* `res.headers` Set some headers to send back to the client\n\n## 🐈 Threading\n\nThreading is a contentious issue when it comes to web frameworks, the age old question of Single vs Multithreaded is enough to start a flame war. \n\nSo let's fight the fire with fire and solve it once and for all.\n\n### 👸 Queue Types\n\nA Flame app can take a type of either `.serial` or `.concurrent`. These do exactly as they say on the tin and allow for either all requests to be handled via `DispatchQueue.main` or `DispatchQueue.global()`. \n\n### Why did we do this?\n\nWe think that giving you the power to choose which type you want for your app is a *good* thing. We're not sorry.\n\nJust as an FYI, we chose to go with `.serial` as the default setting. It was a 50/50 chance we got it right. Good thing it can be changed.\n\n### Example\n\n```swift\n// An app which handles only on the main thread.\nlet app = Flame(type: .serial)\n\n// An app which handles on multiple concurrent threads.\nlet app = Flame(type: .concurrent)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felliottminns%2Fblackfire","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felliottminns%2Fblackfire","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felliottminns%2Fblackfire/lists"}