Fastest autocomplete API written in rust 🦀

Overview

rust-autocomplete-api

fastest* autocomplete API written in rust 🦀

*probably

Run it locally

  1. cargo build --release
  2. ./target/release/autocomplete-api-poc

Run it in Docker

  1. docker build -f Dockerfile . -t rust-autocomplete:latest
  2. docker run -d -p 0.0.0.0:3030:3030 --name rust-autocomplete-api rust-autocomplete

Curl example:

curl  --location --request POST 'localhost:3030/autocomplete/v1' \
--header 'Content-Type: application/json' \
--header 'Content-Type: text/plain' \
--data-raw '{
    "term": "sug"
}'
>>["sugar", "sugarfree", "suggest", "suggested", "suggests", "suggestions", "suggestion", "sugars", "sugared", "sugary"]

How does it work?

You can read about HashMap-based autocomplete implementation here, where I've made terminal version of the same autocomplete as a proof of concept.

Performance:

I used hey to measure response time:

Summary:
  Total:	0.9591 secs
  Slowest:	0.0960 secs
  Fastest:	0.0018 secs
  Average:	0.0185 secs
  Requests/sec:	10426.6399
More details

command:

hey -n 10000 -c 200 http://0.0.0.0:3030/autocomplete/v1 -H "Content-Type: application/json" -X POST -d '{"term":"ap"}'

output:

Summary:
  Total:	0.9591 secs
  Slowest:	0.0960 secs
  Fastest:	0.0018 secs
  Average:	0.0185 secs
  Requests/sec:	10426.6399

  Total data:	230000 bytes
  Size/request:	23 bytes

Response time histogram:
  0.002 [1]	|
  0.011 [2222]	|■■■■■■■■■■■■■■■■■■■
  0.021 [4684]	|■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
  0.030 [2032]	|■■■■■■■■■■■■■■■■■
  0.039 [717]	|■■■■■■
  0.049 [169]	|■
  0.058 [26]	|
  0.068 [43]	|
  0.077 [74]	|■
  0.087 [25]	|
  0.096 [7]	|


Latency distribution:
  10% in 0.0085 secs
  25% in 0.0119 secs
  50% in 0.0163 secs
  75% in 0.0222 secs
  90% in 0.0306 secs
  95% in 0.0360 secs
  99% in 0.0705 secs

Details (average, fastest, slowest):
  DNS+dialup:	0.0001 secs, 0.0018 secs, 0.0960 secs
  DNS-lookup:	0.0000 secs, 0.0000 secs, 0.0000 secs
  req write:	0.0001 secs, 0.0000 secs, 0.0149 secs
  resp wait:	0.0180 secs, 0.0018 secs, 0.0763 secs
  resp read:	0.0001 secs, 0.0000 secs, 0.0126 secs

Status code distribution:
  [405]	10000 responses

Also:

Take a look at the same api but in scala + comparison with WFST

You might also like...
Rust HTTP API Template using PostgreSQL, Redis, RabbitMQ, and Hexagonal Architecture

Rust Template HTTP API Rust API Template using PostgreSQL, Redis, RabbitMQ, and Hexagonal Architecture The following template provides a basic structu

This is a simple Api template for Rust ( Axum framework )

Axum-Rust-Rest-Api-Template This project is an open source Rest Api Template built with Rust's Axum framework. Why this project? I have been learning

An API project using Rust, Actix Web and JWT. *WIP*

Actix-web REST API with JWT (WIP) A simple CRUD backend app using Actix-web, Diesel and JWT Require Rust Stable Postgres Or using Docker How to run Ma

Rust Open Source Login/Register API

Actix Web API with Rustls (OpenSSL available/Without SSL/TLS too) This API uses Actix Web to serve secure HTTP endpoints, utilizing Rustls for TLS enc

Grape is a REST-like API framework for Ruby
Grape is a REST-like API framework for Ruby

Grape is a REST-like API framework for Ruby. It's designed to run on Rack or complement existing web application frameworks such as Rails and Sinatra by providing a simple DSL to easily develop RESTful APIs. It has built-in support for common conventions, including multiple formats, subdomain/prefix restriction, content negotiation, versioning and much more.

An tiny web API for @QuarryProtocol

Warlock Warlock is a tiny web API layer around Quarry Protocol and has endpoints to deserialize Quarry accounts like quarries, miners, and rewarders t

A customizable, simple and easy to use json REST API consumer

JACK is a generic JSON API client. It is useful to interact with APIs from multiple services such as Google and Twitter

Print Apple WeatherKit REST API weather conditions and hourly/daily foreacast to the console.
Print Apple WeatherKit REST API weather conditions and hourly/daily foreacast to the console.

weatherkit-rust A Rust CLI program to print current conditions and daily/hourly forecast to the console. Please read authorization.md as you need an A

RESTful Todo API with Actix-web and SeaORM. Documented by swagger-ui

RESTful Todo RESTful Todo API with Actix and SeaORM. Documented by swagger-ui Prerequisites Rust Usage Clone the repository and run the following comm

Owner
Alexander Osipenko
Such Data Science! Awesome Deep Learning! 🐶
Alexander Osipenko
A secure and efficient gateway for interacting with OpenAI's API, featuring load balancing, user request handling without individual API keys, and global access control.

OpenAI Hub OpenAI Hub is a comprehensive and robust tool designed to streamline and enhance your interaction with OpenAI's API. It features an innovat

Akase Cho 30 Jun 16, 2023
An API to track various stats written in Rust. Tracking Github, Wakatime, Spotify, and Duolingo

Null API API For collecting data Explore the docs » View Demo · Report Bug · Request Feature Table of Contents About The Project Built With Getting St

The Null Dev 2 Dec 15, 2022
Rust implementation of the `URLPattern` web API

urlpattern This crate implements the URLPattern web API in Rust. We aim to follow the specification as closely as possible. Contributing We appreciate

Deno Land 40 Dec 14, 2022
A pure Rust implementation of the Web Local Storage API, for use in non-browser contexts

Rust Web Local Storage API A Rust implementation of the Web LocalStorage API, for use in non-browser contexts About the Web Local Storage API MDN docs

RICHΛRD ΛNΛYΛ 10 Nov 28, 2022
Scratch-Containerised Rust GraphQL-API using Dataloaders

Dockerize Graphql Rust More current version at https://github.com/jayy-lmao/rust-cult-graphql-server This project is currently for demonstrating the u

James H. 89 Dec 3, 2022
A Rust Boilerplate server with GraphQL API, Diesel, PostgreSQL, session authentication and JWT

Canduma rust Graphql A Rust authentication server with GraphQL API, Diesel, PostgreSQL session authentication and JWT This repository contains a Graph

Julien Lenne 738 Dec 28, 2022
Implementation of the RealWorld backend API spec in Actix, Rust's powerful actor system and most fun web framework.

Actix codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld spec and API. ❗ (2021/05/13) This cod

Allen 475 Jan 2, 2023
Rust Rest API Stack with User Management

A secure-by-default rest api stack implemented with hyper, tokio, bb8 and postgres. This project is focused on providing end-to-end encryption by default for 12-factor applications. Includes a working user management and authentication backend written in postgresql with async S3 uploading for POST-ed data files.

Jay 10 Dec 25, 2022
Rust Rocket MongoDB token-authorization REST API boilerplate

Rust Rocket MongoDB token-auth REST API boilerplate In this repository, you can find backend Rust rocket mongodb rest-api boilerplate with token autho

null 6 Dec 7, 2022
OpenAI's ChatGPT API wrapper for Rust 🦀

Regarding API changes from December 11th 2022 OpenAI made a change to API, and now requires a cloudflare clearance token. Due to this, authentication

Maksim 15 Jan 3, 2023