{"library":"simple-rest-client","title":"Simple REST Client","description":"Simple REST client for Python 3.8+ that aims to make interacting with REST APIs straightforward. It provides a clean API for defining resources and actions, handles HTTP requests, and parses responses. Currently at version 1.2.1, it follows a stable release cadence with updates addressing bug fixes and minor improvements, focusing on simplicity and ease of use.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install simple-rest-client"],"cli":null},"imports":["from simple_rest_client.client import SimpleRestClient","from simple_rest_client.resource import Resource","from simple_rest_client.exceptions import ClientError"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nfrom simple_rest_client.client import SimpleRestClient\nfrom simple_rest_client.resource import Resource\n\n# Define a resource for users. Basic CRUD actions (list, get, create, update, delete) are\n# automatically available if not overridden or custom actions defined.\nclass UserResource(Resource):\n    pass\n\n# Initialize the client for a public API (e.g., JSONPlaceholder).\n# In a production environment, ensure ssl_verify is True and handle authentication.\nclient = SimpleRestClient(\n    api_root_url=\"https://jsonplaceholder.typicode.com/\",\n    ssl_verify=True, # Always prefer True in production. Set to False only for testing untrusted SSL.\n    headers={\n        \"Authorization\": f\"Bearer {os.environ.get('API_KEY', '')}\"\n    } # Example for authentication token\n)\n\n# Add the user resource to the client, making it accessible via client.users\nclient.add_resource(resource_name=\"users\", resource_class=UserResource)\n\ntry:\n    # Example 1: Get all users\n    print(\"\\nFetching all users...\")\n    all_users = client.users.list()\n    print(f\"First user: {all_users[0]['name']}\")\n\n    # Example 2: Get a single user by ID\n    print(\"\\nFetching user with ID 1...\")\n    user_1 = client.users.get(1)\n    print(f\"User 1 name: {user_1['name']}, email: {user_1['email']}\")\n\n    # Example 3: Create a new user (NOTE: JSONPlaceholder is a fake API; this won't persist)\n    print(\"\\nCreating a new user (API will return 201, but not persist on JSONPlaceholder)...\")\n    new_user_data = {\n        \"name\": \"Jane Doe\",\n        \"username\": \"janedoe\",\n        \"email\": \"jane.doe@example.com\",\n        \"address\": {\"street\": \"123 Main St\"}\n    }\n    created_user = client.users.create(new_user_data)\n    print(f\"Created user ID: {created_user.get('id', 'N/A')}, Name: {created_user['name']}\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n","lang":"python","description":"This quickstart demonstrates how to initialize `SimpleRestClient`, define a `Resource` class, and perform common REST operations like `list`, `get`, and `create` against a public API. It includes an example of handling authentication headers and emphasizes best practices like enabling SSL verification.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}