Search by Algolia
How personalization boosts customer engagement
e-commerce

How personalization boosts customer engagement

You land on your favorite retailer’s website, where everything seems to be attractively arranged just for you. Your favorite ...

Jon Silvers

Director, Digital Marketing

What is retail analytics and how can it inform your data-driven ecommerce merchandising strategy?
e-commerce

What is retail analytics and how can it inform your data-driven ecommerce merchandising strategy?

There is such tremendous activity both on and off of retailer websites today that it would be impossible to make ...

Catherine Dee

Search and Discovery writer

8 ways to use merchandising data to boost your online store ROI
e-commerce

8 ways to use merchandising data to boost your online store ROI

New year, new goals. Sounds positive, but looking at your sales data, your revenue and profit aren’t so hot ...

John Stewart

VP, Corporate Communications and Brand

Algolia DocSearch + Astro Starlight
engineering

Algolia DocSearch + Astro Starlight

What is Astro Starlight? If you're building a documentation site, your content needs to be easy to write and ...

Jaden Baptista

Technical Writer

What role does AI play in recommendation systems and engines?
ai

What role does AI play in recommendation systems and engines?

You put that in your cart. How about this cool thing to go with it? You liked that? Here are ...

Catherine Dee

Search and Discovery writer

How AI can help improve your user experience
ux

How AI can help improve your user experience

They say you get one chance to make a great first impression. With visual design on ecommerce web pages, this ...

Jon Silvers

Director, Digital Marketing

Keeping your Algolia search index up to date
product

Keeping your Algolia search index up to date

When creating your initial Algolia index, you may seed the index with an initial set of data. This is convenient ...

Jaden Baptista

Technical Writer

Merchandising in the AI era
e-commerce

Merchandising in the AI era

For merchandisers, every website visit is an opportunity to promote products to potential buyers. In the era of AI, incorporating ...

Tariq Khan

Director of Content Marketing

Debunking the most common AI myths
ai

Debunking the most common AI myths

ARTIFICIAL INTELLIGENCE CAN’T BE TRUSTED, shouts the headline on your social media newsfeed. Is that really true, or is ...

Vincent Caruana

Senior Digital Marketing Manager, SEO

How AI can benefit the retail industry
ai

How AI can benefit the retail industry

Artificial intelligence is on a roll. It’s strengthening healthcare diagnostics, taking on office grunt work, helping banks combat fraud ...

Catherine Dee

Search and Discovery writer

How ecommerce AI is reshaping business
e-commerce

How ecommerce AI is reshaping business

Like other modern phenomena such as social media, artificial intelligence has landed on the ecommerce industry scene with a giant ...

Vincent Caruana

Senior Digital Marketing Manager, SEO

AI-driven smart merchandising: what it is and why your ecommerce store needs it
ai

AI-driven smart merchandising: what it is and why your ecommerce store needs it

Do you dream of having your own personal online shopper? Someone familiar and fun who pops up every time you ...

Catherine Dee

Search and Discovery writer

NRF 2024: A cocktail of inspiration and innovation
e-commerce

NRF 2024: A cocktail of inspiration and innovation

Retail’s big show, NRF 2024, once again brought together a wide spectrum of practitioners focused on innovation and transformation ...

Reshma Iyer

Director of Product Marketing, Ecommerce

How AI-powered personalization is transforming the user and customer experience
ai

How AI-powered personalization is transforming the user and customer experience

In a world of so many overwhelming choices for consumers, how can you best engage with the shoppers who visit ...

Vincent Caruana

Senior Digital Marketing Manager, SEO

Unveiling the future: Algolia’s AI revolution at NRF Retail Big Show
algolia

Unveiling the future: Algolia’s AI revolution at NRF Retail Big Show

Get ready for an exhilarating journey into the future of retail as Algolia takes center stage at the NRF Retail ...

John Stewart

VP Corporate Marketing

How to master personalization with AI
ai

How to master personalization with AI

Picture ecommerce in its early days: businesses were just beginning to discover the power of personalized marketing. They’d divide ...

Ciprian Borodescu

AI Product Manager | On a mission to help people succeed through the use of AI

5 best practices for nailing the ecommerce virtual assistant user experience
ai

5 best practices for nailing the ecommerce virtual assistant user experience

“Hello there, how can I help you today?”, asks the virtual shopping assistant in the lower right-hand corner ...

Vincent Caruana

Senior Digital Marketing Manager, SEO

Add InstantSearch and Autocomplete to your search experience in just 5 minutes
product

Add InstantSearch and Autocomplete to your search experience in just 5 minutes

A good starting point for building a comprehensive search experience is a straightforward app template. When crafting your application’s ...

Imogen Lovera

Senior Product Manager

Looking for something?

facebookfacebooklinkedinlinkedintwittertwittermailmail

A product-based JavaScript API client should be able to run in the browser, with direct front-end DOM access, as well as in a node environment, to access back-end servers and services.

Additionally, a product-based API client should provide exhaustive and easy access to all features of the application it serves. And it should keep up-to-date with every new feature.

Finally, an API client should add extra value to the application, by adding such functionality as:

  • Retry logic, to sidestep network or any other momentary glitch or timeout
  • Rate-limits and throttling strategies, to reduce server load and usage costs 
  • Batch processing, where the API performs a set of actions to accomplish a single common task
  • And other helper functionality 
  • Friendly view of underlying Rest API

What is a product-based API client?

An API (application programming interface) is not just a wrapper; it’s a separate, light-weight application that enables developers to interact with a full-featured software platform.

A product-based API is an API that a company sells as a product. Google sells the Google Maps API, Stripe sells a financial API, and we sell a Search API. 

A product-based API client is an API that comes in different programming languages, frameworks, and JavaScript flavors. Our clients sit on top of different REST API endpoints. 

By offering an API client in a developer’s own language, they get the benefit of:

  • Faster onboarding to implement the basic and advanced features of an application
  • Simpler integration into their own codebases
  • Large amounts of code already written for them, including retries, throttling, and batching

The best API design also tries to limit the amount of boilerplate code needed to instantiate, use, or parameterize an API method.

We can name a few other defining characteristics of a product-based API client:

  • Small code size
  • Low or no dependencies
  • Flexible customization with smart parameters 
  • Intuitive DX in the naming and usage of requests and responses (improvement over Rest API)
  • Thorough API documentation and tutorials
  • Non-breaking versioning
  • Authentication with API keys or tokens
  • Simple and universal data exchanges with JSON
  • Keeping up to date with changes and best practices in the underlying programming languages and technologies

How to improve an API product from version to version

First a word about process: We have over 10,000 customers using our API clients. With that kind of usage, we are in a good position to fine-tune our APIs based on customer support tickets, chats, and usage statistics in our logs. 

However, an even greater source of truth is our own engineers. Our APIs are not just used by our customers. Our Dashboard uses our JavaScript, PHP, Ruby, and other API clients; we have inhouse use cases that implement our API clients; our client-facing tech support teams create demos, prototypes, and solutions using our API clients. With all that API testing and internal usage, we know first-hand the pain points and positive aspects of our API clients. 

With all that feedback, every release includes:

  • Refactoring the interface and the code behind (non-breaking) to keep up with the changing standards and evolutions of the underlying technology. For example, our newest version of our JavaScript client supports ES6 and TypeScript. 
  • Improving the DX for all kinds of developers – experienced, beginners, domain experts.
  • Targeting more use cases. New or existing methods to better address certain use cases, sometimes even adopting the jargon of an industry.  
  • Generating a common interface across all API languages. Many customers switch between different languages. Having a common interface helps with that. Using JSON also helps.

Some upgrades we’ve made to our JavaScript API client

For SaaS companies like ours, a JavaScript API client is critical, because of its ability to request services directly from our cloud servers without requiring customers to go though their own back-end servers. Among other things, client-side API requests improve the response time of the new API and simplify the front-end code on the front end. Because of these benefits, our JavaScript API is our most used client.

With that in mind, JavaScript APIs have to manage the challenges of client-side application development, as well as the particularities of the JavaScript language and its flavors like React, Vue, and Angular. 

Here are some improvements we’ve made recently:

Support for both require and import, and default and lite versions

// For the default version
const algoliasearch = require('algoliasearch');
 
// For the default version
import algoliasearch from 'algoliasearch';
 
// For the search only version
import algoliasearch from 'algoliasearch/lite';

Parameterized instantiation

We started with a simple instantiation – client application id and the API key:

const algoliasearch = algoliasearch('YourApplicationID', 'YourAdminAPIKey');

Then we added a third parameter, allowing the developer to customize a number of additional features:

const algoliasearch = algoliasearch(
   'YourApplicationID',
   'YourSearchOnlyAPIKey',
{
   timeouts: {
       connect: 1,
       read: 2,
       write: 30,
   },
   requester: createBrowserXhrRequester(),
   logger: createConsoleLogger(LogLevelEnum.Error),
   responsesCache: createInMemoryCache(),
   requestsCache: createInMemoryCache({ serializable: false }),
   hostsCache: createFallbackableCache({
       caches: [
           createBrowserLocalStorageCache({ key: `${version}-${appId}` }),
           createInMemoryCache(),
       ],
   }),
});

As you can see, the third parameter allows developers to define:

  • Unique timeouts
  • The behavior of requesters
  • Customizations for node requests or a browser environment
  • Log callbacks
    • Logging enables us to follow the lifecycle of a client, to record and then analyze API activity.
    • Recording API activity helps us improve the usage of an API in future versions. It also enables us to reduce pricing by removing certain common usages from the costs.
    • Also, by allowing developers to send us their own logging methods, we can store the information they think is important, thus improving the quality of our own logs.
  • Response caching
    • Developers can manage their own throttling, for example.
    • They can disable our response caching, as well.
    • They can manage local storage, preserving the state of search even after a browser refreshes.
  • Request caching
    • Allows promise sharing, for example.

Reduced size of the JavaScript

Make the client tree shakeable:

// Tree shakable ( 1 kb, dead code elimination )
// list the methods you use and don’t include the code of any other method  
const client = createSearchClient({
   // ..
   methods: { search }
}); 

Customized requests 

Experts sometimes require a non-opinionated, open request to handle unexpected use cases. For example, developers can pass read/write requests to cover what is not in the API:

client.transporter.read ({
   path: '',
   verb: 'GET'
});

Note on logging: when we log these customized requests, we can take that information to create new methods in the future.

Reducing dependencies to zero

You can achieve zero-dependency simply by following JavaScript standards and using Typescript.

Batching common, multi-tasked operations

Instead of a single Save() method, we added more robust methods like replaceAllObjects(), reindex(), copyIndex(). This helps ensure best practices in such data-sensitive methods. Additionally, we’ve written all the code that manages retries and zero-downtime logic.

Typescript support

javascript typescript

Managing the release schedule

Last but not least, a product-based API client must follow the best strategies for testing and release practices. We’ll leave testing to another blog, but here’s the overall strategy we use for our release cycle:

  • Release a beta version for internal use cases, applications, and demos
  • Work with the Docs team to standardize and document the DX
  • Help upgrade products that rely on our API clients
  • Release a final beta to a handful of customers
  • Release the stable version, along with the updated Docs
  • Promote and encourage migration via Support calls, blog posts, and social media
About the author
Peter Villani

Sr. Tech & Business Writer

linkedinmediumtwitter

Recommended Articles

Powered byAlgolia Algolia Recommend

What is an API?
product

Catherine Dee

Search and Discovery writer

Ruby Client v2 is out!
engineering

Chloé Liban

Software Egineer

Announcing the new JavaScript API Client v4
engineering

Nuno Maduro

Software engineer at Algolia