{"id":42338339,"url":"https://github.com/jankstar/cosmos_db_restapi","last_synced_at":"2026-01-27T14:36:36.822Z","repository":{"id":62866149,"uuid":"559270934","full_name":"jankstar/cosmos_db_restapi","owner":"jankstar","description":"Golang Package for the cosmos db rest api","archived":false,"fork":false,"pushed_at":"2022-12-02T10:06:59.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-06-20T09:23:03.809Z","etag":null,"topics":["cosmos-db","golang","rest-api"],"latest_commit_sha":null,"homepage":"","language":"Go","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/jankstar.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":"2022-10-29T15:39:04.000Z","updated_at":"2023-03-01T18:55:18.000Z","dependencies_parsed_at":"2023-01-22T22:15:42.952Z","dependency_job_id":null,"html_url":"https://github.com/jankstar/cosmos_db_restapi","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/jankstar/cosmos_db_restapi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jankstar%2Fcosmos_db_restapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jankstar%2Fcosmos_db_restapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jankstar%2Fcosmos_db_restapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jankstar%2Fcosmos_db_restapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jankstar","download_url":"https://codeload.github.com/jankstar/cosmos_db_restapi/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jankstar%2Fcosmos_db_restapi/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28815247,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-27T12:25:15.069Z","status":"ssl_error","status_checked_at":"2026-01-27T12:25:05.297Z","response_time":168,"last_error":"SSL_read: 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":["cosmos-db","golang","rest-api"],"created_at":"2026-01-27T14:36:36.670Z","updated_at":"2026-01-27T14:36:36.808Z","avatar_url":"https://github.com/jankstar.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# golang_cosmos_db_restapi\ngolang sql api for cosmos db\n\n```go get github.com/jankstar/golang_cosmos_db_restapi```\n\n# Prerequisites\ngo version 1.18+\n\n# Function\n\n## GetAuthorizationTokenUsingMasterKey\nGetAuthorizationTokenUsingMasterKey function for generating access token\nhttps://docs.microsoft.com/en-us/rest/api/cosmos-db/access-control-on-cosmosdb-resources\n\n### Parameters:\n\tVerb: \"GET\"\n\tRessourcentyp: \"dbs\"\n\tResource Linkage: \"dbs/ToDoList\"\n\tDate: \"Thu, 27 Apr 2017 00:51:12 GMT\"\n\tmasterKey: \"dsZQi3KtZmCv1ljt3VNWNm7sQUF1y5rJfC6kv5JiwvW0EndXdDku/dkKBp8/ufDToSxLzR4y+O/0H/t4bQtVNw==\"\n\n### Return:\t\n\tauthorization: \"typ%3dmaster%26ver%3d1.0%26sig%3dc09PEVJrgp2uQRkr934kFbTqhByc7TVr3OHyqlu%2bc%2bc%2bc%3d\"\n\n## ExecuteQuerry\nExecuteQuerry - execute a query as rest api\n\nhttps://docs.microsoft.com/en-us/rest/api/cosmos-db/querying-cosmosdb-resources-using-the-rest-api\n### Parameters:\n\tendpoint_uri - uri from cosmos db\n\tmaster_key - masker key from cosmos db\n\tdatabase - name of database\n\tcontainer - name of container\n\tpartitionkey - optional partition key else \"\"\n\tmax_item_count - optional max item count else 0\n\tquerry - like TQuery\n\n### Returns:\n\tStatus - response status i.e. 200 ok\n\tBody - response body as string\n\tContinuation - the Continuation-token if there are more items to read\n\n## CreateDocument\nCreateDocument - create or rewrite an object by ID via rest api\n\nhttps://docs.microsoft.com/en-us/rest/api/cosmos-db/create-a-document\n### Parameters:\n\tendpoint_uri - uri from cosmos db\n\tmaster_key - master key from cosmos db\n\tdatabase - name of database\n\tcontainer - name of container\n\tpartitionkey - optional partition (if container defined with partion key, it is required)\n\tupset -- optional boolean, true: create or update, if exist\n\tdata - json data as sting of the item\n\n### Returns:\n\tStatus - response status i.e. 201 Created\n\tBody - response body as string\n\n## GetDocumentByID\nGetDocumentByID - get an object by ID via rest api\n\nhttps://docs.microsoft.com/en-us/rest/api/cosmos-db/get-a-document\n### Parameters:\n\tendpoint_uri - uri from cosmos db\n\tmaster_key - master key from cosmos db\n\tdatabase - name of database\n\tcontainer - name of container\n\tpartitionkey - optional partition (if container defined with partion key, it is required)\n\tid - id of the item\n\n### Returns:\n\tStatus - response status i.e. 200 ok\n\tBody - response body as string\n\n\n## DeleteDocumentByID\nDeleteDocumentByID - delete an object by ID via rest api\n\nhttps://docs.microsoft.com/en-us/rest/api/cosmos-db/delete-a-document\n### Parameters:\n\tendpoint_uri - uri from cosmos db\n\tmaster_key - master key from cosmos db\n\tdatabase - name of database\n\tcontainer - name of container\n\tpartitionkey - optional partition (if container defined with partion key, it is required)\n\tid - id of the item\n\n### Returns:\n\tStatus - response status i.e. 204 No Content \n\tBody - response body as string i.e. \"\"\n\t\n## Example 1 - native operations\n```go\nfunc test() {\n\t//get the \"endpoint\" and master-key from the .env file\n\tgodotenv.Load(\".env\")\n\tendpoint := os.Getenv(\"ENDPOINT_URI\")\n\tkey := os.Getenv(\"MASTER_KEY\")\n\n\tvar querry = TQuery{\n\t\tQuery: \"SELECT * FROM c WHERE c.word = @word1 OR c.word = @word2 \",\n\t\tParameters: []TParameter{\n\t\t\t{\n\t\t\t\tName:  \"@word1\",\n\t\t\t\tValue: \"Zwerg\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tName:  \"@word2\",\n\t\t\t\tValue: \"Nase\",\n\t\t\t}},\n\t}\n\n\treq_continuation := \"\"\n\tsteps := 0\n\tfor req_continuation != \"\" || steps == 0 {\n\t\tsteps += 1\n\t\tfmt.Println(\"Step:\", steps)\n\n\t\tres_status, res_body, res_continuation := ExecuteQuerry(\n\t\t\tendpoint, key,\n\t\t\t\"lerneria-express\", \"dictionary\", \"\", //no patition key\n\t\t\t3, req_continuation, //only 3 documents per request\n\t\t\tquerry)\n\t\tfmt.Println(\"Status: \" + res_status)\n\t\t//last \"continuation\" header becomes new request value\n\t\treq_continuation = res_continuation\n\n\t\tvar MyBody TBody\n\t\t_ = json.Unmarshal([]byte(res_body), \u0026MyBody)\n\t\tfmt.Println(\"Count: \" + strconv.Itoa(int(MyBody.Count)))\n\t\tfmt.Println(\"continuation:\", res_continuation)\n\t\tfmt.Println(\"Documents:\")\n\t\tfor _, doc := range MyBody.Documents {\n\n\t\t\t//mapping the interface{} element to struc\n\t\t\ttype Dic struct {\n\t\t\t\tEtag      string `mapstructure:\"_etag\"`\n\t\t\t\tRid       string `mapstructure:\"_rid\"`\n\t\t\t\tID        string `mapstructure:\"id\"`\n\t\t\t\tWord      string `mapstructure:\"word\"`\n\t\t\t\tSnippet   string `mapstructure:\"snippet\"`\n\t\t\t\tCreatedAt string `mapstructure:\"created_at\"`\n\t\t\t}\n\t\t\tvar MyDic Dic\n\t\t\tmapstructure.Decode(doc, \u0026MyDic)\n\n\t\t\tfmt.Println(MyDic)\n\t\t}\n\t}\n\n}\n```\n\n## Example 2 - object-like operations\n```go\nfunc test() {\n\t//get the \"endpoint\" and master-key from the .env file\n\tgodotenv.Load(\".env\")\n\tendpoint := os.Getenv(\"ENDPOINT_URI\")\n\tkey := os.Getenv(\"MASTER_KEY\")\n\n\tvar querry = TQuery{\n\t\tQuery: \"SELECT * FROM c WHERE c.word = @word1 OR c.word = @word2 \",\n\t\tParameters: []TParameter{\n\t\t\t{\n\t\t\t\tName:  \"@word1\",\n\t\t\t\tValue: \"Zwerg\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tName:  \"@word2\",\n\t\t\t\tValue: \"Nase\",\n\t\t\t}},\n\t}\n\n\tcontainer := ContainerFactory(\n\t\tDatabaseFactory(\n\t\t\tendpoint,\n\t\t\tkey,\n\t\t\t\"lerneria-express\"),\n\t\t\"dictionary\",\n\t\t\"\")\n\n\tcontainer.OpenQuerry(3, querry) //set query for fetching with 3 docs\n\n\tfor {\n\t\tres_status, res_body := container.Fetch() //fetching data\n\t\tfmt.Println(\"Status: \" + res_status)\n\t\tif !strings.Contains(res_status, \"200\") || res_body == \"\" {\n\t\t\tbreak //Cancel because error\n\t\t}\n\n\t\tvar MyBody TBody\n\t\t_ = json.Unmarshal([]byte(res_body), \u0026MyBody)\n\t\tfmt.Println(\"Count: \" + strconv.Itoa(int(MyBody.Count)))\n\t\tfmt.Println(\"continuation:\", container.Continuation)\n\t\tfmt.Println(\"Documents:\")\n\t\tfor _, doc := range MyBody.Documents {\n\n\t\t\t//mapping the interface{} element to struc\n\t\t\ttype Dic struct {\n\t\t\t\tEtag      string `mapstructure:\"_etag\"`\n\t\t\t\tRid       string `mapstructure:\"_rid\"`\n\t\t\t\tID        string `mapstructure:\"id\"`\n\t\t\t\tWord      string `mapstructure:\"word\"`\n\t\t\t\tSnippet   string `mapstructure:\"snippet\"`\n\t\t\t\tCreatedAt string `mapstructure:\"created_at\"`\n\t\t\t}\n\t\t\tvar MyDic Dic\n\t\t\tmapstructure.Decode(doc, \u0026MyDic)\n\n\t\t\tfmt.Println(MyDic)\n\t\t}\n\t}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjankstar%2Fcosmos_db_restapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjankstar%2Fcosmos_db_restapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjankstar%2Fcosmos_db_restapi/lists"}