Getting started overview

Integrating with the ReSmush.it API involves a straightforward process from account creation to sending your first image optimization request. The service is designed to compress images, reducing file sizes to improve website loading times and overall performance. ReSmush.it offers a free tier that allows unlimited image optimizations for files up to 5MB in size via its API, making it accessible for initial development and smaller-scale projects. For users on the WordPress platform, a dedicated plugin provides a no-code solution for automatic image optimization upon upload. Developers can utilize the API directly to integrate image compression into custom applications, leveraging a simple HTTP POST request structure. The API's primary function is to accept an image URL and return a compressed version, along with metadata about the compression. This guide focuses on the steps required to set up your environment and execute a successful API call.

Before proceeding, ensure you have:

  • An internet connection.
  • Access to a development environment for making HTTP requests (e.g., cURL, Postman, a programming language with HTTP client libraries).
  • A publicly accessible image URL for testing your first request.

Quick reference table

Step What to do Where
1. Review Documentation Understand API endpoints and parameters. ReSmush.it API documentation
2. Prepare Image URL Ensure you have a publicly accessible image URL for testing. Your web server or an image hosting service
3. Construct Request Formulate an HTTP POST request with the image URL. Your preferred HTTP client (e.g., cURL, Postman)
4. Send Request Execute the POST request to the ReSmush.it API endpoint. Your development environment
5. Process Response Parse the JSON response to retrieve the optimized image URL and data. Your application logic

Create an account and get keys

ReSmush.it's API operates without requiring explicit API keys for its free tier. Unlike many other API services that mandate registration and key generation for authentication, ReSmush.it allows direct access to its image optimization endpoint for images up to 5MB. This design simplifies the getting started process, as developers can immediately begin making requests without an account setup phase. For scenarios requiring higher limits or enterprise-grade features, custom pricing and arrangements are available, which would likely involve a direct consultation and potential API key provision. However, for initial testing and usage within the free tier's constraints, no specific account creation or key retrieval steps are necessary.

This approach streamlines the developer experience, enabling quicker integration and proof-of-concept development. Developers can proceed directly to constructing and sending their first API request as soon as they have a publicly accessible image to optimize. The absence of an API key requirement means that authentication headers or query parameters related to credentials are not part of the standard request for the free service. This also implies that rate limiting and usage tracking for the free tier are managed based on IP addresses or other heuristics rather than individual API keys.

Your first request

To make your first request to the ReSmush.it API, you will send an HTTP POST request to their API endpoint, including the URL of the image you wish to optimize. The API expects a JSON payload containing the src parameter, which is the URL of your image, and optionally a quality parameter to specify the desired compression level. The quality parameter accepts values from 0 to 100, where 100 indicates the highest quality (least compression) and 0 indicates the lowest quality (most compression). If not specified, the API applies a default optimization level.

API Endpoint

The primary API endpoint for image optimization is https://api.resmush.it/.

Request Parameters

  • src (required): A string representing the publicly accessible URL of the image to be optimized.
  • quality (optional): An integer between 0 and 100, indicating the desired image quality. Default is typically around 92 for JPEG images, balancing file size and visual fidelity.

Example Request (cURL)

This cURL command demonstrates how to send an image for optimization:

curl -X POST \
-H "Content-Type: application/json" \
-d '{"src":"https://example.com/your-image.jpg", "quality": 90}' \
https://api.resmush.it/

Replace https://example.com/your-image.jpg with the actual URL of an image you want to optimize. Ensure this image is publicly accessible and less than 5MB in size.

Example Response

Upon a successful request, the API will return a JSON object containing details about the optimized image. The response includes the original and optimized file sizes, the compression ratio, and the URL of the compressed image.

{
  "src": "https://example.com/your-image.jpg",
  "src_size": 123456,
  "dest": "https://cdn.resmush.it/path/to/optimized-image.jpg",
  "dest_size": 45678,
  "percent": 63.0,
  "quality": 90,
  "error": null
}
  • src: The original image URL submitted.
  • src_size: The size of the original image in bytes.
  • dest: The URL of the optimized image. This URL is hosted by ReSmush.it and can be used directly in your applications.
  • dest_size: The size of the optimized image in bytes.
  • percent: The percentage of size reduction achieved.
  • quality: The quality setting used for optimization.
  • error: Will be null on success, or contain an error message if the request failed.

You can then use the dest URL to display the optimized image on your website or in your application. It is recommended to store this URL or the optimized image itself on your own infrastructure for better control and performance.

Common next steps

After successfully optimizing your first image, consider these common next steps to integrate ReSmush.it more deeply into your workflow:

  1. Automate Image Optimization: Implement a system to automatically optimize images as they are uploaded or created. For web applications, this might involve integrating the ReSmush.it API into your image upload pipeline. For WordPress users, the ReSmush.it WordPress plugin handles this automatically.

  2. Handle Different Image Formats: ReSmush.it supports common image formats like JPEG, PNG, and GIF. Test with various formats to ensure consistent optimization results across your assets. Be aware that the effectiveness of compression can vary significantly between formats and image content.

  3. Error Handling and Retries: Implement robust error handling in your application to gracefully manage failed API requests. This includes scenarios like invalid image URLs, images exceeding the 5MB limit, or temporary API service unavailability. Consider retry mechanisms with exponential backoff for transient errors, as recommended by Google Cloud's best practices for API retries.

  4. Store Optimized Images: While ReSmush.it provides a temporary URL for the optimized image, it is generally advisable to download and store the optimized image on your own server or Content Delivery Network (CDN). This provides greater control over content delivery, reduces reliance on external services for serving assets, and can improve long-term performance and reliability.

  5. Monitor Performance: Regularly monitor the impact of image optimization on your website's performance metrics, such as page load times. Tools like Google Lighthouse or web analytics platforms can help assess the improvements. Continuous monitoring helps validate the effectiveness of the optimization strategy and identify areas for further enhancement.

  6. Explore Advanced Options: For scenarios requiring higher image size limits, dedicated support, or specific enterprise features, explore the custom enterprise pricing options available through ReSmush.it's official channels. This might involve direct contact with their sales team to discuss specific requirements and potential service level agreements.

Troubleshooting the first call

Encountering issues during your first API call is common. Here are some troubleshooting steps for common problems with the ReSmush.it API:

Common Error Messages and Solutions

  • {"error":"Invalid image URL"}:

    • Cause: The src URL provided is not a valid image URL, is malformed, or points to a resource that is not an image.
    • Solution: Double-check the URL for typos. Ensure the URL points directly to an image file (e.g., ends in .jpg, .png, .gif) and is publicly accessible. Test the URL in a web browser to confirm it loads correctly.
  • {"error":"Image too large"}:

    • Cause: The image at the provided src URL exceeds the 5MB file size limit for the free tier.
    • Solution: Use a smaller image for testing. If you require optimization for larger images, you will need to contact ReSmush.it for custom enterprise solutions.
  • No response or connection timeout:

    • Cause: Network issues, firewall blocking, or temporary unavailability of the ReSmush.it API server.
    • Solution: Verify your internet connection. Check if there are any firewall rules on your network or server preventing outbound requests to https://api.resmush.it/. Wait a few minutes and retry the request, as it might be a temporary service interruption.
  • {"error":"Could not fetch image"}:

    • Cause: The ReSmush.it server could not access the image URL. This could be due to the image being behind authentication, on a private network, or the server hosting the image blocking ReSmush.it's IP addresses.
    • Solution: Ensure the image URL is publicly accessible without any authentication or IP restrictions. If the image is on your server, check server logs for any blocked requests from ReSmush.it's user agent or IP ranges.
  • Incorrect Content-Type header:

    • Cause: The request was sent without the Content-Type: application/json header, or with an incorrect one.
    • Solution: Ensure your HTTP client explicitly sets the Content-Type header to application/json, as the API expects a JSON payload.

When troubleshooting, it is helpful to use tools like cURL or Postman to isolate the API call from your application logic. This allows you to confirm whether the issue lies with your request parameters, network environment, or the API itself. Always refer to the official ReSmush.it API documentation for the most up-to-date information on error codes and best practices.