{"id":33167537,"url":"https://github.com/open-coap/java-coap","last_synced_at":"2026-01-14T01:56:41.958Z","repository":{"id":42686827,"uuid":"444765486","full_name":"open-coap/java-coap","owner":"open-coap","description":"CoAP Java library","archived":false,"fork":false,"pushed_at":"2025-11-06T08:05:44.000Z","size":2493,"stargazers_count":28,"open_issues_count":8,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-11-20T18:03:49.228Z","etag":null,"topics":["coap","coap-client","coap-protocol","coap-server"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"PelionIoT/java-coap","license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/open-coap.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-01-05T10:44:04.000Z","updated_at":"2025-11-06T07:59:40.000Z","dependencies_parsed_at":"2024-02-28T09:44:47.427Z","dependency_job_id":"5724dba2-262d-40dc-894c-4ff11ac8e2f9","html_url":"https://github.com/open-coap/java-coap","commit_stats":null,"previous_names":[],"tags_count":51,"template":false,"template_full_name":null,"purl":"pkg:github/open-coap/java-coap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-coap%2Fjava-coap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-coap%2Fjava-coap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-coap%2Fjava-coap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-coap%2Fjava-coap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/open-coap","download_url":"https://codeload.github.com/open-coap/java-coap/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-coap%2Fjava-coap/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28408692,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T00:40:43.272Z","status":"ssl_error","status_checked_at":"2026-01-14T00:40:42.636Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":["coap","coap-client","coap-protocol","coap-server"],"created_at":"2025-11-16T00:00:45.513Z","updated_at":"2026-01-14T01:56:41.942Z","avatar_url":"https://github.com/open-coap.png","language":"Java","readme":"CoAP's library for JVM\n======================\n\n![Maven Central](https://img.shields.io/maven-central/v/io.github.open-coap/coap-core)\n[![License](https://img.shields.io/badge/license-Apache%202.0-brightgreen.svg)](LICENSE)\n![Status:Production](https://img.shields.io/badge/Project%20status-Production-brightgreen.svg)\n[![codecov](https://codecov.io/gh/open-coap/java-coap/branch/master/graph/badge.svg?token=8XE69RTQIZ)](https://codecov.io/gh/open-coap/java-coap)\n\nIntroduction\n------------\n\nThis library makes it possible to create jvm enabled device or coap based services. It can also help to emulate an\nembedded device for prototyping and testing purposes.\n\nThe following features are supported by the library:\n\n* Complete CoAP support\n    - The Constrained Application Protocol [RFC 7252](https://tools.ietf.org/html/rfc7252)\n    - Observing Resources in the Constrained Application Protocol [RFC 7641](https://tools.ietf.org/html/rfc7641)\n    - Block-Wise Transfers in the Constrained Application Protocol [RFC 7959](https://tools.ietf.org/html/rfc7959)\n    - PATCH and FETCH Methods [RFC 8132](https://tools.ietf.org/html/rfc8132)\n* Partial support for [RFC 9175](https://datatracker.ietf.org/doc/html/rfc9175)\n  - Request-Tag support for blockwise transfers\n  - Client side handling of echo challenge\n* CoRE Link Format processing API\n    - Constrained RESTful Environments (CoRE) Link Format [RFC 6690](https://tools.ietf.org/html/rfc6690)\n* CoAP server mode\n* CoAP client mode\n* Coap over tcp, tls [RFC 8323](https://tools.ietf.org/html/rfc8323)\n    - excluding: websockets, observations with BERT blocks\n* Network transports:\n    - UDP (plain text)\n    - TCP (plain text)\n    - DTLS 1.2 with CID (using mbedtls)\n        - X509 Certificate\n        - PSK\n    - TLS\n* ~~LwM2M TLV and JSON data formats~~ (deprecated)\n\n### Fork\n\nThis project started as a fork from https://github.com/PelionIoT/java-coap, but it has changed significantly, so it became project of its own.\n\n### Integrations:\n\n- micrometer: metrics\n- mbedtls: DTLS transport\n- netty: UDP and DTLS only\n\nRuntime requirements\n------------\n\n* JRE 8, 17, 21\n\nUsing the Library\n-----------------\n\n### Gradle\n\nAdd to your `build.gradle.kts`\n\n```kotlin\ndependencies {\n  ...\n  implementation(\"io.github.open-coap:coap-core:VERSION\")\n  implementation(\"io.github.open-coap:coap-mbedtls:VERSION\") // for DTLS support\n  implementation(\"io.github.open-coap:coap-tcp:VERSION\")     // for coap over tcp support\n  implementation(\"io.github.open-coap:coap-metrics:VERSION\") // for micrometer integration\n  implementation(\"io.github.open-coap:coap-netty:VERSION\")   // for netty integration\n}\n```\n\n### Maven\n\nAdd dependency into your `pom.xml`:\n\n```xml\n\n\u003cdependency\u003e\n  \u003cgroupId\u003eio.github.open-coap\u003c/groupId\u003e\n  \u003cartifactId\u003ecoap-core\u003c/artifactId\u003e\n  \u003cversion\u003e{VERSION}\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n### Coap client simple usage:\n\n```java\n// build CoapClient that connects to coap server which is running on port 5683\nCoapClient client = CoapServer.builder()\n        .transport(udp())\n        .buildClient(new InetSocketAddress(\"localhost\", 5683));\n\n// send request\nCoapResponse resp = client.sendSync(CoapRequest.get(\"/sensors/temperature\"));\nLOGGER.info(resp.toString());\n\nclient.close();\n```\n\n### Coap client complete usage:\n\n```java\n// build CoapClient that connects to coap server which is running on port 5683\nclient = CoapServer.builder()\n        // define transport, plain text UDP listening on random port\n        .transport(udp())\n        // (optional) register observation listener to handle incoming observations\n        .notificationsReceiver((resourceUriPath, observation) -\u003e {\n            LOGGER.info(\"Observation: {}\", observation);\n            // in case of block transfer, call to retrieve rest of payload\n            CompletableFuture\u003cOpaque\u003e payload = retrieveRemainingBlocks(resourceUriPath, observation, req -\u003e client.send(req));\n            return true; // return false to terminate observation\n        })\n        // (optional) set custom observation relation store, for example one that will use external storage\n        .observationsStore(new HashMapObservationsStore())\n        // (optional) define maximum block size\n        .blockSize(BlockSize.S_1024)\n        // (optional) set maximum response timeout, default for every request\n        .responseTimeout(Duration.ofMinutes(2))\n        // (optional) set maximum allowed resource size\n        .maxIncomingBlockTransferSize(1000_0000)\n        // (optional) set extra filters (interceptors) to outbound pipeline\n        .outboundFilter(\n                // each request will be set with different Token\n                TokenGeneratorFilter.sequential(1)\n        )\n        // build client with target server address\n        .buildClient(new InetSocketAddress(\"localhost\", 5683));\n\n// send ping\nclient.ping();\n\n// send request\nCompletableFuture\u003cCoapResponse\u003e futureResponse = client.send(CoapRequest.get(\"/sensors/temperature\"));\nfutureResponse.thenAccept(resp -\u003e\n        // .. handle response\n        LOGGER.info(resp.toString())\n);\n\n// send request with payload and header options\nCompletableFuture\u003cCoapResponse\u003e futureResponse2 = client.send(CoapRequest\n        .post(\"/actuator/switch\")\n        // set header options, for example:\n        .options(opt -\u003e opt\n                .etag(Opaque.decodeHex(\"0a8120\"))\n                .accept(MediaTypes.CT_APPLICATION_JSON)\n                .maxAge(Duration.ofHours(1))\n        )\n        .payload(\"{\\\"power\\\": \\\"on\\\"}\", MediaTypes.CT_APPLICATION_JSON)\n        .addContext(TransportContext.RESPONSE_TIMEOUT, Duration.ofMinutes(3)) // overwrite default response timeout\n);\nfutureResponse2.thenAccept(resp -\u003e\n        // .. handle response\n        LOGGER.info(resp.toString())\n);\n\n// observe (subscribe) to a resource, observations will be handled by observation listener\nCompletableFuture\u003cCoapResponse\u003e resp3 = client.send(CoapRequest.observe(\"/sensors/temperature\"));\nLOGGER.info(resp3.join().toString());\n\nclient.close();\n```\n\n### Server usage\n\n```java\n// define subscription manager for observable resources\nObserversManager observersManager = new ObserversManager();\n\nserver = CoapServer.builder()\n        // configure with plain text UDP transport, listening on port 5683\n        .transport(new DatagramSocketTransport(5683))\n        // define routing\n        // (note that each resource function is a `Service` type and can be decorated/transformed with `Filter`)\n        .route(RouterService.builder()\n                .get(\"/.well-known/core\", req -\u003e\n                        CoapResponse.ok(\"\u003c/sensors/temperature\u003e\", MediaTypes.CT_APPLICATION_LINK__FORMAT).toFuture()\n                )\n                .post(\"/actuators/switch\", req -\u003e {\n                    // ...\n                    return coapResponse(Code.C204_CHANGED).toFuture();\n                })\n                // observable resource\n                .get(\"/sensors/temperature\", observersManager.then(req -\u003e\n                        CoapResponse.ok(\"21C\").toFuture()\n                ))\n        )\n        .build();\n\nobserversManager.init(server);\nserver.start();\n```\n\n### Services and Filters\n\nAll requests are handled by implementing `Service\u003cREQ, RES\u003e` interface, which is a simple function:\n\n```\n(REQ) -\u003e CompletableFuture\u003cRES\u003e\n```\n\nIntercepting is achieved by implementing `Filter` interface, which is again a simple function:\n\n```\n(REQ, Service\u003cIN_REQ, IN_RES\u003e) -\u003e CompletableFuture\u003cRES\u003e\n```\n\nFilter interface has a set of helper functions to compose with another `Filter` and `Service`.\nTogether it creates a pipeline of request handling functions.\n\nIt is following \"server as a function\" design concept. It is a very simple, flexible and testable way to model data processing in a pipeline.\nIt is best describe in this white paper: [Your Server as a Function](https://monkey.org/~marius/funsrv.pdf), and has a great implementation in [Finagle](https://twitter.github.io/finagle) project.\n\n#### Decorating services with filters\n\nEvery `Service` implementation can be decorated with `Filter`. It can be used to implement any kind of authorisation, authentication, validation, rate limitations etc.\n\nFor example, if we want to limit allowed payload size, it could be done:\n\n```\n  MaxAllowedEntityFilter filter = new MaxAllowedEntityFilter(100, \"too big\")\n  \n  Service\u003cCoapRequest, CoapResponse\u003e filteredRoute = filter.then(route)\n```\n\nAnother example, is to use auto generated `etag` for responses and validate it in requests:\n\n```\n  EtagGeneratorFilter filter2 = new EtagGeneratorFilter()\n  EtagValidatorFilter filter3 = new EtagValidatorFilter()\n  \n  Service\u003cCoapRequest, CoapResponse\u003e filteredRoute = filter3.andThen(filter2).then(route)\n```\n\nAll request handling filters are under package [..coap.server.filter](coap-core/src/main/java/com/mbed/coap/server/filter).\n\n\nCoap command line client\n--------------\n\nThis [coap-cli](coap-cli) module provides command line utility.\n\n\nDevelopment\n-----------\n\n### Requirements:\n\n* JDK 17\n* gradle\n\n### Useful commands:\n\n- `./gradlew build`                             build\n- `./gradlew publishToMavenLocal`               publish to local maven\n- `./gradlew dependencyUpdates`                 determine which dependencies have updates\n- `./gradlew useLatestVersions`                 update dependencies to the latest available versions\n- `./gradlew wrapper --gradle-version VERSION`  Upgrading the Wrapper version\n\nContributions\n-------------\n\nAll contributions are Apache 2.0. Only submit contributions where you have authored all of the code. If you do this on work time make sure your employer is OK with this.\n\nLicense\n-------\n\nUnless specifically indicated otherwise in a file, files are licensed under the Apache 2.0 license, as can be found in: [LICENSE](LICENSE)\n","funding_links":[],"categories":["Protocol Library"],"sub_categories":["CoAP"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopen-coap%2Fjava-coap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopen-coap%2Fjava-coap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopen-coap%2Fjava-coap/lists"}