Artisyn API
    Artisyn API
    • INTRODUCTION
    • Auth
      • OAUTH
        • Google
        • Google Callback
      • Login
        POST
      • Register
        POST
      • Verify Account
        PUT
      • Logout
        DELETE
      • Forgot Password
        POST
      • Reset Password
        PUT
    • Admin
      • Categories
        • List Categories
        • Create Category
        • Get Category
        • Update Category
        • Delete Category
    • Categories
      • List Categories
        GET
      • Get Category
        GET
    • Curator
      • Artisans
        • List Artisans
        • Create Artisan
        • Show Artisan
        • Update Artisan
        • Toggle Activation
        • Bulk Operation
        • Delete Artisan
    • Index
      POST

    INTRODUCTION

    Handling File Uploads with PUT Requests#

    When calling update endpoints or other endpoints that require file uploads and for the request to be a PUT request, do note that PUT requests do not natively support file uploads in most frontend environments due to limitations in handling multipart form data.
    As a work around, The Artisyn API uses method spoofing to support HTTP methods like PUT for update requests.
    To take advantage of this, you can use a POST request and include the X-HTTP-Method: PUT header to emulate a PUT request.
    This allows you to upload files while maintaining the intended PUT semantics for updating resources.

    Key Points:#

    Why use this workaround:
    The Artisyn API expects PUT for updating resources (e.g., updating an artisan's profile), but file uploads require multipart/form-data, which PUT does not support natively.
    How it works:
    Send a POST request with the X-HTTP-Method: PUT header. The API will interpret it as a PUT request.
    When to use:
    Use this approach when updating resources that include file uploads, such as profile images or documents.
    Usage Example:
    Below is an example of how to update an artisan's profile, including a file upload (e.g., a profile picture), using JavaScript with the fetch API:

    Additional Notes#

    API Endpoint:
    Replace /api/curator/artisans/${artisanId} with the target update endpoint.
    Error Handling:
    Always handle errors to provide feedback to users, especially for network issues or API validation errors.
    Security:
    Ensure the request includes any required authentication tokens (e.g., Bearer token in the Authorization header) as per the API's authentication requirements.
    Next
    Google
    Built with