{"id":13705012,"url":"https://github.com/nning/david","last_synced_at":"2025-05-05T12:32:55.372Z","repository":{"id":22126735,"uuid":"25457490","full_name":"nning/david","owner":"nning","description":"CoAP server with Rack interface.","archived":true,"fork":false,"pushed_at":"2021-05-21T02:06:00.000Z","size":347,"stargazers_count":37,"open_issues_count":21,"forks_count":11,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-26T21:06:23.655Z","etag":null,"topics":["coap","coap-server","rack","rails","ruby"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","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/nning.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}},"created_at":"2014-10-20T08:30:28.000Z","updated_at":"2023-10-19T15:35:18.000Z","dependencies_parsed_at":"2022-08-19T15:10:08.687Z","dependency_job_id":null,"html_url":"https://github.com/nning/david","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nning%2Fdavid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nning%2Fdavid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nning%2Fdavid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nning%2Fdavid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nning","download_url":"https://codeload.github.com/nning/david/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252497733,"owners_count":21757672,"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":["coap","coap-server","rack","rails","ruby"],"created_at":"2024-08-02T22:00:29.912Z","updated_at":"2025-05-05T12:32:55.041Z","avatar_url":"https://github.com/nning.png","language":"Ruby","readme":"# David\n\n[![Gem Version](https://img.shields.io/gem/v/david.svg)](http://badge.fury.io/rb/david)\n[![Build Status](https://img.shields.io/travis/nning/david.svg)](https://travis-ci.org/nning/david)\n[![Coverage Status](https://img.shields.io/coveralls/nning/david.svg)](https://coveralls.io/r/nning/david)\n[![Code Climate](https://codeclimate.com/github/nning/david/badges/gpa.svg)](https://codeclimate.com/github/nning/david)\n[![Docker Hub Build Status](https://img.shields.io/docker/build/nning2/david.svg)](https://hub.docker.com/r/nning2/david/)\n\nDavid is a CoAP server with Rack interface to bring the illustrious family of\nRack compatible web frameworks into the Internet of Things. It is tested with\nMRI \u003e= 2.3, and JRuby \u003e= 9.1. David version ~\u003e 0.5.0 aims for Rack 2 (and Rails\n5). Compatibility to Rails 4 is available in version ~\u003e 0.4.5.\n\n## Quick Start\n\nJust include David in your Gemfile!\n\n    gem 'david'\n\nIt will hook into Rack and make itself the default handler, so running `rails\ns` starts David. If you want to start WEBrick for example, you can do so by\nexecuting `rails s webrick`.\n\n**For now, you have to remove the `web-console` gem from the Gemfile (which is\nHTTP specific anyway) if you use Rails/David in CoAP only mode.** You probably\nalso want to disable [CSRF\nprotection](http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection/ClassMethods.html)\nby removing the `protect_from_forgery` line from\n`app/controllers/application_controller.rb` (or use `:null_session` if you know\nwhat you are doing).\n\nThe [`coap-rails-dummy`](https://github.com/nning/coap-rails-dummy) repository\ndocuments [changes to a newly generated Ruby on Rails application for a quick\nstart](https://github.com/nning/coap-rails-dummy/compare/initial...master).\n\nAfter the server is started, the Rails application is available at\n`coap://[::1]:3000/` by default. (Although you have to set a route for `/` in\n`config/routes.rb`, of course.)\n\n[Copper](https://addons.mozilla.org/de/firefox/addon/copper-270430/) is a CoAP\nclient for Firefox and can be used for development. The [Ruby coap\ngem](https://github.com/nning/coap) is used by David for example for message\nparsing and also includes a command line utility (named `coap`) that can also\nbe used for development.\n\nAs [CoAP](https://tools.ietf.org/html/rfc7252) is a protocol for constrained\nenvironments and machine to machine communications, returning HTML from your\ncontrollers will not be of much use. JSON for example is more suitable in that\ncontext. The Accept header is set to \"application/json\" by default, so that\nRails responds with the JSON resource representation. David works well with the\ndefault ways to handle JSON responses from controllers such as `render json:`.\nYou can also utilize [Jbuilder templates](https://github.com/rails/jbuilder)\nfor easy generation of more complex JSON structures.\n\n[CBOR](https://tools.ietf.org/html/rfc7049) can be used to compress your JSON.\nAutomatic transcoding between JSON and CBOR is activated by setting the Rack\nenvironment option `CBOR` or `config.coap.cbor` in your Rails application\nconfig to `true`.\n\n## Tested Rack Frameworks\n\nBy providing a Rack interface, David does not only work with Rails but also\nwith the following Rack compatible web frameworks.\n\n* [Grape](https://github.com/intridea/grape)\n* [Hobbit](https://github.com/patriciomacadden/hobbit)\n* [NYNY](https://github.com/alisnic/nyny)\n* Plain Rack\n* [Sinatra](https://github.com/sinatra/sinatra)\n* [Rails](https://github.com/rails/rails)\n* [Roda](https://github.com/jeremyevans/roda)\n\n## Configuration\n\nThe following table lists available configuration options for the CoAP server.\nRack keys can be specified with the `-O` option of `rackup`. The listed Rails\nkeys can be accessed for example from the `config/application.rb` file of your\nRails application.\n\n| Rack key\t\t\t| Rails key\t\t\t\t\t| Default\t\t\t\t| Semantics\t\t\t\t\t\t\t|\n|---\t\t\t\t|---\t\t\t\t\t\t|---\t\t\t\t\t|---\t\t\t\t\t\t\t\t|\n| Block\t\t\t\t| coap.block\t\t\t\t| true\t\t\t\t\t| [Blockwise transfers](https://tools.ietf.org/html/draft-ietf-core-block-16) |\n| CBOR\t\t\t\t| coap.cbor\t\t\t\t\t| false\t\t\t\t\t| JSON/CBOR transcoding\t\t\t\t|\n| DefaultFormat\t\t| coap.default_format\t\t|\t\t\t\t\t\t| Default Content-Type\t\t\t\t|\n| Host\t\t\t\t|\t\t\t\t\t\t\t| ::1 / ::\t\t\t\t| Server listening host\t\t\t\t|\n| Log\t\t\t\t|\t\t\t\t\t\t\t| info\t\t\t\t\t| Log level (none or debug)\t\t\t|\n| MinimalMapping\t|\t\t\t\t\t\t\t| false\t\t\t\t\t| Minimal HTTP status codes mapping\t|\n| Multicast\t\t\t| coap.multicast\t\t\t| true\t\t\t\t\t| Multicast support\t\t\t\t\t|\n| MulticastGroups\t| coap.multicast_groups\t\t| ff02::fd, ff05::fd\t| Multicast group configuration\t\t|\n| Observe\t\t\t| coap.observe\t\t\t\t| true\t\t\t\t\t| [Observe support](https://tools.ietf.org/html/draft-ietf-core-observe-16) |\n|\t\t\t\t\t| coap.only\t\t\t\t\t| true\t\t\t\t\t| Removes (HTTP) middleware\t\t\t|\n| Port\t\t\t\t|\t\t\t\t\t\t\t| 5683\t\t\t\t\t| Server listening port\t\t\t\t|\n|\t\t\t\t\t| coap.resource_discovery\t| true\t\t\t\t\t| Provision of `.well-known/core`\t|\n\nThe server can be started with debug log level for example with the following\ncommand provided that a rackup config file (`config.ru`) exists like in a Rails\napplication.\n\n    rackup -O Log=debug\n\nIn a Rails application, CBOR transcoding is activated for any controller and\naction by inserting the third line of the following code into\n`config/application.rb`.\n\n    module Example\n\t  class Application \u003c Rails::Application\n\t    config.coap.cbor = true\n\t  end\n\tend\n\nIn Copper for example the default block size for Blockwise Transfers is set to\n64 bytes. That's even small for most exception messages. It is recommended to\nset the block size to the maximum (1024B) during development.\n\n## Discovery\n\nThe [CoAP Discovery](https://tools.ietf.org/html/rfc7252#section-7) will be\nactivated by default. A `.well-known/core` resource automatically returns the\nresources you defined in Rails. You can annotate this resources with attributes\nlike an interface description (`if`) or the content type (`ct`). (See\n[RFC6690](https://tools.ietf.org/html/rfc6690) or [the\ncode](https://github.com/nning/coap/blob/master/lib/core/link.rb#L8) for\nfurther documentation.)\n\n    class ThingsController \u003c ApplicationController\n      discoverable \\\n        default: { if: 'urn:things', ct: 'application/cbor' },\n        index:   { if: 'urn:index' }\n\n      def show\n        render json: Thing.find(params[:id])\n      end\n\n      def index\n        render json: Thing.all\n      end\n\tend\n\n## Rack environment\n\nDavid sets the following server (and protocol) specific Rack environment\nentries that can be read from your Rack application if necessary.\n\n| Key\t\t\t\t| Value class\t| Semantics |\n|---\t\t\t\t|---\t\t\t|--- |\n| coap.version\t\t| Integer\t\t| Protocol version of CoAP request |\n| coap.multicast\t| Boolean\t\t| Marks whether request was received via multicast |\n| coap.dtls\t\t\t| String\t\t| DTLS mode (as defined in [section 9 of RFC7252](https://tools.ietf.org/html/rfc7252#section-9)) |\n| coap.dtls.id\t\t| String\t\t| DTLS identity |\n| coap.cbor\t\t\t| Object\t\t| Ruby object deserialized from CBOR |\n\n## Benchmarks\n\nDavid handles about 12,500 requests per second in MRI and 14,000 in JRuby\n(tested in MRI 2.3.0 and JRuby 1.7.19 with up to 10,000 concurrent clients on a\nsingle core of a Core i7-3520M CPU running Linux 3.18.6).\n\n## Caveats\n\n* Incoming block-wise transfer is not supported.\n* Automatically generating `.well-known/core` is only supported in Rails.\n\n## Copyright\n\nThe code is published under the MIT license (see the LICENSE file).\n\n### Authors\n\n* [henning mueller](https://nning.io)\n","funding_links":[],"categories":["Libraries"],"sub_categories":["Ruby"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnning%2Fdavid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnning%2Fdavid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnning%2Fdavid/lists"}