crystal_kemal
Crystal/Kemal JSON API Server
This is a JSON API server built with Kemal in Crystal. It is designed to be compared with an Actix-web server. While Actix-web is known for its safety and speed, Kemal offers faster development and easier maintenance.
Read more : https://studiozenkai.com/post/crystal-high-performance/
Getting Started
Prerequisites
Make sure you have Crystal installed on your machine. You can install it using Homebrew:
brew install crystal
Installation
Clone the repository and navigate into the project directory:
git clone git@github.com:heri/crystal_pure_api.git
cd crystal_pure_api
Install the required dependencies:
shards install
psql -U postgres
CREATE DATABASE profiling;
\c profiling
CREATE TABLE users (id SERIAL PRIMARY KEY, firstName VARCHAR(255));
Seed the table with the 10,000 rows the /db benchmark endpoint reads from:
bin/seed
Running the Application
Compile the application:
crystal build main.cr --release
Crystal runs single-threaded per process, so main.cr binds with reuse_port and bin/server starts one worker process per CPU core, letting the kernel load-balance connections across them:
KEMAL_PORT=3000 bin/server
Set WORKERS to override the worker count instead of using all cores.
Each worker keeps its own Postgres connection pool, sized by DB_POOL_SIZE (default 25) so connections are pre-warmed instead of opened and closed on demand under load.
The server should now be running and accessible at http://localhost:3000.
Endpoints
- GET /json: Returns a static JSON payload with no database access. Mirrors TechEmpower's JSON Serialization test.
- GET /db: Fetches one row out of the 10,000-row users table by a server-generated random id. Mirrors TechEmpower's Single Database Query test.
- GET /users: Returns a list of users in HTML format.
- POST /webhook: Updates a user's first name. Expects a JSON payload with firstName and Id.
Contributing
Feel free to submit issues and pull requests.
License
This project is licensed under the MIT License.
crystal_kemal
- 0
- 0
- 0
- 0
- 4
- about 5 hours ago
- October 23, 2019
Mon, 06 Jul 2026 14:11:04 GMT