{"id":19519769,"url":"https://github.com/ep2p/somnia-sample","last_synced_at":"2026-06-19T05:31:19.863Z","repository":{"id":126685321,"uuid":"366723791","full_name":"ep2p/somnia-sample","owner":"ep2p","description":"Sample application made on top of Somnia","archived":false,"fork":false,"pushed_at":"2021-06-26T13:24:40.000Z","size":30,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-21T22:02:27.957Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ep2p.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2021-05-12T13:24:09.000Z","updated_at":"2021-06-26T13:24:42.000Z","dependencies_parsed_at":"2023-06-17T16:15:58.630Z","dependency_job_id":null,"html_url":"https://github.com/ep2p/somnia-sample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ep2p/somnia-sample","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ep2p%2Fsomnia-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ep2p%2Fsomnia-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ep2p%2Fsomnia-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ep2p%2Fsomnia-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ep2p","download_url":"https://codeload.github.com/ep2p/somnia-sample/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ep2p%2Fsomnia-sample/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34519048,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-19T02:00:06.005Z","response_time":61,"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-11-11T00:21:42.299Z","updated_at":"2026-06-19T05:31:19.840Z","avatar_url":"https://github.com/ep2p.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# somnia-sample\n\nSmall sample application made on top of Somnia to show an example.\n\n## How to run\n\nYou need to run two or more nodes of this application, then store data or retrieve data from it.\n\nRequirements:\n- Java 8+\n- maven\n- Running MongoDB instance\n\n### Get the project\n\nClone the project to your system and go to the main directory of project (where POM file is)\n\n### Make and run node 1 (ID: 2)\n```sh\n mvn spring-boot:run -Dspring-boot.run.arguments=\"--nodeId=2 --server.port=8002 --server.host=localhost\"\n```\nThis builds project and runs the server on port `8002`.\nWe are not making any changes to mongodb, so make sure mongo is accessible on localhost and default port or pass the arguments that you need.\nA database with name `somnia-sample-1` will be created in your mongoDB instance\n\n### Make and run node 2 (ID: 3)\n```sh\nmvn spring-boot:run -Dspring-boot.run.arguments=\"--nodeId=3 --server.port=8003 --server.host=localhost --spring.data.mongodb.database=somnia-sample-2\"\n```\nWe run the second node with ID of `3` on port `8003`.\nNote that we are passing different mongodb database name to this one.\n\n### Bootstrap nodes\n\nLets bootstrap node 2 with 3:\n\n```shell\ncurl --request POST \\\n  --url http://localhost:8002/api/bootstrap/3 \\\n  --header 'Content-Type: application/json' \\\n  --data '{\n\t\"address\": \"http://localhost:8003\"\n}'\n```\n\n### Store\n\nLets store data using node 2:\n\n```shell\ncurl --request POST \\\n  --url http://localhost:8002/storage/store/3 \\\n  --header 'Content-Type: application/json' \\\n  --data '{\n\t\"name\": \"Michel\",\n\t\"lastname\": \"Scott\"\n}'\n```\n\nThe **key** we chose for the data is `3` as you see in the url.\nId of `3` is closer to node `3` rather than node `2`, and thats where we are expecting data to be persisted.\n\nCheck the mongodb database of node 3 to make sure data is persisted.\n\n### Get (Retrieve)\n\nNow lets get data of ID `3` from node `2`\n\n```shell\ncurl --request GET \\\n  --url http://localhost:8002/storage/get/3 \\\n  --header 'Content-Type: application/json'\n```\n\nOutput:\n\n```json\n{\n  \"name\": \"Michel\",\n  \"lastname\": \"Scott\",\n  \"nickname\": null\n}\n```\n\nStop the node 2 and try the same request. This time lets ask node 3 itself to make sure it has same output.\n\n```shell\ncurl --request GET \\\n  --url http://localhost:8002/storage/get/3 \\\n  --header 'Content-Type: application/json'\n```\n\n\nDone :)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fep2p%2Fsomnia-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fep2p%2Fsomnia-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fep2p%2Fsomnia-sample/lists"}