{"id":26410719,"url":"https://github.com/chadnpc/poshrest","last_synced_at":"2025-03-17T20:19:13.094Z","repository":{"id":282758805,"uuid":"949444960","full_name":"chadnpc/PoshRest","owner":"chadnpc","description":"A module for working with HTTP RESTful APIs.","archived":false,"fork":false,"pushed_at":"2025-03-16T18:39:49.000Z","size":34,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-16T19:43:51.598Z","etag":null,"topics":["http","powershell","rest-api"],"latest_commit_sha":null,"homepage":"https://www.powershellgallery.com/packages/PoshRest","language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"wtfpl","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chadnpc.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}},"created_at":"2025-03-16T13:35:57.000Z","updated_at":"2025-03-16T18:39:52.000Z","dependencies_parsed_at":"2025-03-16T19:53:56.694Z","dependency_job_id":null,"html_url":"https://github.com/chadnpc/PoshRest","commit_stats":null,"previous_names":["chadnpc/poshrest"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chadnpc%2FPoshRest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chadnpc%2FPoshRest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chadnpc%2FPoshRest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chadnpc%2FPoshRest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chadnpc","download_url":"https://codeload.github.com/chadnpc/PoshRest/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244102830,"owners_count":20398386,"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":["http","powershell","rest-api"],"created_at":"2025-03-17T20:19:12.699Z","updated_at":"2025-03-17T20:19:13.082Z","avatar_url":"https://github.com/chadnpc.png","language":"PowerShell","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿# PoshRest\n\n[![Build Status](https://github.com/chadnpc/PoshRest/actions/workflows/build_module.yaml/badge.svg)](https://github.com/chadnpc/PoshRest/actions) [![PowerShell Gallery](https://img.shields.io/powershellgallery/v/PoshRest.svg)](https://www.powershellgallery.com/packages/PoshRest) [![Downloads](https://img.shields.io/powershellgallery/dt/PoshRest.svg)](https://www.powershellgallery.com/packages/PoshRest)\n\nA lightweight PowerShell module for working with HTTP RESTful APIs.\n\nIf you want advanced features beyond basic [`Invoke-RestMethod`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-restmethod) while maintaining PowerShell syntax, then this module is for you.\n\nStuff like:\n\n- **Caching**: GET request caching\n- **Serialization**: JSON/XML with custom options\n- **Retry Policies**: Automatic retries with backoff strategies\n- **Custom Auth**: Scriptblock-based authentication handlers\n- **File Uploads** : MultipartFormData with files\n\n\n## Installation\n\n```powershell\nInstall-Module PoshRest -Scope CurrentUser\n```\n\n## Basic Usage\n\n```powershell\nImport-Module PoshRest\n\n# Create client with base URL\n$client = [PoshRest]::new(\"https://api.restful-api.dev\")\n\n# Configure defaults\n$client.AddDefaultHeader(\"X-API-Key\", \"your-api-key\").SetAuthentication(\"Bearer\", \"your-token\").ConfigureRetry(5, [TimeSpan]::FromSeconds(2)).EnableCache()\n\n# Create request with URL segment\n$request = [PoshRestRequest]::new(\"users/{id}\", [HttpMethod]::Get)\n$request\n    .AddParameter(\"id\", 123, [ParameterType]::UrlSegment)\n    .AddHeader(\"Accept\", \"application/json\")\n\n# Execute synchronously\n$response = $client.Execute($request)\n\nif ($response.IsSuccessful) {\n    $user = $response.Content | ConvertFrom-Json\n    Write-Host \"User: $($user.name)\"\n} else {\n    Write-Error \"Request failed: $($response.StatusCode)\"\n}\n```\n\n## Feature Examples\n\n### 1. Chainable Configuration\n\n  ```powershell\n  $client = [PoshRest]::new(\"https://api.restful-api.dev\")\n      .AddDefaultHeader(\"User-Agent\", \"MyApp/1.0\")\n      .AddDefaultParameter(\"api-version\", \"2.0\", [ParameterType]::QueryString)\n  ```\n\n### 2. All Parameter Types\n\n  ```powershell\n  $request = [PoshRestRequest]::new(\"data\", [HttpMethod]::Post)\n  $request\n      .AddParameter(\"page\", 2, [ParameterType]::QueryString)\n      .AddParameter(\"auth\", \"token\", [ParameterType]::Header)\n      .AddParameter(\"userId\", 456, [ParameterType]::UrlSegment)\n      .AddParameter(\"rememberMe\", $true, [ParameterType]::Cookie)\n      .AddBody(@{name=\"John\"; age=30})\n  ```\n\n### 3. XML/JSON Serialization\n\n  ```powershell\n  # JSON with custom options\n  $client.JsonOptions.PropertyNamingPolicy = [JsonNamingPolicy]::SnakeCase\n\n  # XML with namespaces\n  $client.ConfigureXml(\n      [XmlSerializerNamespaces]::new(@([XmlQualifiedName]::new(\"ns\", \"http://example.com\"))),\n      [XmlWriterSettings]::new() | Add-Member -MemberType NoteProperty -Name Indent -Value $true\n  )\n\n  $request.AddXmlBody([PSCustomObject]@{Name=\"John\"; Age=30})\n  ```\n\n### 4. Cookie Management\n\n  ```powershell\n  $client.AddCookie(\"session\", \"abc123\", \"api.restful-api.dev\", \"/api\")\n  ```\n\n### 5. File Upload\n\n  ```powershell\n  $request = [PoshRestRequest]::new(\"uploads\", [HttpMethod]::Post)\n  $request\n      .AddFile(\"profile\", \"C:\\profile.jpg\") |\n      .AddBody(@{userId=123})\n  ```\n\n### 6. Retry Policies\n\n  ```powershell\n  $client.ConfigureRetry(3, [TimeSpan]::FromSeconds(1))\n  ```\n\n### 7. Caching\n\n  ```powershell\n  $client.EnableCache()\n  $client.Execute([PoshRestRequest]::new(\"cached-data\", [HttpMethod]::Get))\n  ```\n\n### 8. Custom Authentication\n\n  ```powershell\n  $client.SetAuthenticator({\n      param($req)\n      $req.RequestMessage.Headers.Add(\"X-Dynamic-Header\", (Get-Random))\n  })\n  ```\n\n### 9. URL Segments\n\n  ```powershell\n  $request = [PoshRestRequest]::new(\"products/{category}/{id}\", [HttpMethod]::Get)\n  $request\n      .AddParameter(\"category\", \"electronics\", [ParameterType]::UrlSegment)\n      .AddParameter(\"id\", 789, [ParameterType]::UrlSegment)\n  ```\n\n### 10. Async Execution\n\n  ```powershell\n  $client.ExecuteAsync($request) | Wait-Job | Receive-Job\n  ```\n\n\n## Community\n\n@[GitHub Discussions](https://github.com/chadnpc/PoshRest/discussions) are open for Feature requests \u0026 Troubleshooting help.\n\n## License\n\nReleased under the [WTFPL License 🍷🗿](LICENSE).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchadnpc%2Fposhrest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchadnpc%2Fposhrest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchadnpc%2Fposhrest/lists"}