{"id":25448115,"url":"https://github.com/sinakhanjani/restfulapi","last_synced_at":"2025-09-03T12:36:28.222Z","repository":{"id":275627807,"uuid":"926598975","full_name":"sinakhanjani/restfulapi","owner":"sinakhanjani","description":"RestfulAPI is a lightweight yet powerful Swift framework for making RESTful API requests using URLSession and Combine, featuring built-in authentication management, custom headers, and support for synchronous and asynchronous execution. 🚀","archived":false,"fork":false,"pushed_at":"2025-02-03T17:23:05.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-17T19:18:49.024Z","etag":null,"topics":["combine-framework","restful-api","swift","urlsession"],"latest_commit_sha":null,"homepage":"","language":"Swift","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/sinakhanjani.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":"2025-02-03T14:43:32.000Z","updated_at":"2025-02-03T17:24:06.000Z","dependencies_parsed_at":"2025-02-03T18:35:13.962Z","dependency_job_id":"1a67570e-2b84-47a4-a8fc-5186b5643a1b","html_url":"https://github.com/sinakhanjani/restfulapi","commit_stats":null,"previous_names":["sinakhanjani/restfulapi"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinakhanjani%2Frestfulapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinakhanjani%2Frestfulapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinakhanjani%2Frestfulapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinakhanjani%2Frestfulapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sinakhanjani","download_url":"https://codeload.github.com/sinakhanjani/restfulapi/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254485051,"owners_count":22078767,"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":["combine-framework","restful-api","swift","urlsession"],"created_at":"2025-02-17T19:18:50.738Z","updated_at":"2025-05-16T07:09:13.522Z","avatar_url":"https://github.com/sinakhanjani.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RestfulAPI\n\n**RestfulAPI** is a lightweight, yet powerful Swift framework designed for seamless interaction with RESTful web services. It provides an easy-to-use API built on top of `URLSession` and `Combine`, supporting modern asynchronous programming patterns. With built-in authentication management, multiple request execution methods, and structured response handling, this framework simplifies network operations in iOS applications.\n\n## ✨ Key Features\n- **Easy API Requests** – Simplified request handling with `URLSession` and `Combine`\n- **Multiple Execution Methods** – Support for `DispatchQueue`, `DispatchSemaphore`, and `async/await`\n- **Authentication Management** – Built-in token-based authentication with `Authentication` and `AuthorizationType`\n- **Custom Headers Support** – Easily attach custom headers to API requests\n- **Automatic Encoding \u0026 Decoding** – JSON serialization support for request bodies and responses\n- **Swift Package Manager (SPM) Support** – Easy integration into projects\n\n## 🛠 Installation\n### Swift Package Manager (SPM)\nAdd the following dependency to your `Package.swift` file:\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/your-repo/RestfulAPI.git\", from: \"1.0.0\")\n]\n```\n\nOr use Xcode’s `File \u003e Swift Packages \u003e Add Package Dependency` and enter the repository URL.\n\n## ⚙️ Configuration\nBefore making requests, configure the API settings:\n\n```swift\nRestfulAPIConfiguration().setup { () -\u003e APIConfiguration in\n    APIConfiguration(baseURL: \"https://your-api.com\",\n                     headers: [\"Authorization\": \"Bearer token\"])\n}\n```\n\n## 🔐 Authentication\nThis framework provides built-in authentication management:\n\n### 1️⃣ Setting Authentication Type\nYou can set the type of authentication using `AuthorizationType`:\n\n```swift\npublic enum AuthorizationType: Codable {\n    case bearerToken\n    case token\n    case basicAuth\n}\n```\n\n### 2️⃣ Managing Authentication Tokens\nThe `Authentication` class helps in managing tokens:\n\n```swift\nvar auth = Authentication.auth1\n\n// Authenticate a user\nauth.authenticate(token: \"your_token_here\")\n\n// Check if user is logged in\nif auth.isLogin {\n    print(\"User is logged in\")\n}\n\n// Logout user\nauth.logout()\n```\n\n## 🚀 Usage\n\n### 1️⃣ Fetch with `Combine`\nUse `fetchDataTaskPublisherRequest` for handling API responses using `Combine`:\n\n```swift\nvar fetchRequest = RestfulAPI\u003cEmpty, Example\u003e(path: \"/todos/1\")\n    .with(method: .GET)\n\nfetchRequest\n    .fetchDataTaskPublisherRequest { result in\n        switch result {\n        case .success(let example):\n            print(example)\n        case .failure(let error):\n            print(\"Error:\", error)\n        }\n    }\n```\n\n### 2️⃣ Fetch with `URLSession` (Completion Handler)\nUse `sendURLSessionRequest` for handling API responses with a completion handler:\n\n```swift\nRestfulAPI\u003cEmpty, Example\u003e(path: \"/todos/1\")\n    .sendURLSessionRequest { result in\n        switch result {\n        case .success(let example):\n            print(example)\n        case .failure(let error):\n            print(\"Error:\", error)\n        }\n    }\n```\n\n### 3️⃣ Fetch with `DispatchSemaphore` (Synchronous Request)\nUse this method when you need to wait for the API response synchronously:\n\n```swift\nlet response = try? RestfulAPI\u003cEmpty, Example\u003e(path: \"/todos/1\")\n    .sendURLSessionRequest()\n```\n\n### 4️⃣ Adding Headers\nYou can add custom headers to your API requests:\n\n```swift\nRestfulAPI\u003cEmpty, Example\u003e(path: \"/todos/1\")\n    .with(headers: [\"Custom-Header\": \"Value\"])\n```\n\n### 5️⃣ Encoding \u0026 Decoding Response\nThe framework provides built-in methods for encoding requests and decoding responses:\n\n```swift\npublic func decodeResponse(data: Data) throws -\u003e Response\npublic func encodeResponse() throws -\u003e Data\n```\n\n### 6️⃣ Available HTTP Methods\nThe following HTTP methods are supported:\n\n```swift\npublic enum Method: String {\n    case GET, POST, PUT, DELETE, PATCH\n}\n```\n\n## 📝 License\nThis project is licensed under the MIT License. See the `LICENSE` file for details.\n\n## 💡 Contributing\nContributions are welcome! Feel free to create issues or submit pull requests.\n\n---\n\nThis `README.md` now includes structured documentation with headers, proper explanations, and a cleaner format for better readability.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsinakhanjani%2Frestfulapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsinakhanjani%2Frestfulapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsinakhanjani%2Frestfulapi/lists"}