• Stars
    star
    43
  • Rank 645,449 (Top 13 %)
  • Language
    Crystal
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

RealWorld back-end API implementation 👍

Crystal World logo

Built with Crystal Build status Awesome vladfaust.com

Welcome to the Crystal World, a RealWorld back-end API application implemented in Crystal!

About

This project aims to demonstrate of how simple and enjoyable it is to develop a high-performance web application in Crystal, which is proven to be both fast and slick language, featuring:

  • ⚡️ Efficiency comparable to C
  • 🍃 Beauty inherited from Ruby
  • 🔒 Type system with smart compiler

Crystal World relies on Onyx framework as its foundation. The database chosen is SQLite. Go ahead and read the source code, you'll find it delightfully simple and understandeable! 🍰

Note that although Crystal itself is not officially released yet, it's already being used in many real-world (including business) applications.

Installation

Clone this repository with

> git clone https://github.com/vladfaust/crystalworld.git && cd crystalworld

Crystal is a compiled language. It has different compilation modes, e.g. development and production. Production code is faster and packed into a single binary, however its builds take more time. Therefore, there are multiple ways to proceed:

Production build with Docker

  1. Build an image:
> docker build -t crystalworld:latest .
  1. Apply migrations:
> docker run -e DATABASE_URL="sqlite3://./crystalworld.db" crystalworld bin/cake db:migrate
  1. Launch the server
> docker run -p 5000:5000 -e DATABASE_URL="sqlite3://./crystalworld.db" \
-e JWT_SECRET_KEY="63a051d73d71c997d38946f82e708301" crystalworld

Production build from the source code

  1. Install Crystal on your machine
  2. Set env vars
> export DATABASE_URL="sqlite3://./crystalworld.db" CRYSTAL_ENV=production \
JWT_SECRET_KEY="63a051d73d71c997d38946f82e708301"
  1. Build the app
> time shards build --production --release --no-debug --progress --stats
  1. Apply migrations
> ./bin/cake db:migrate
  1. Launch the server
> ./bin/server

Development build from the source code

  1. Install Crystal on your machine
  2. Create an /.env.development.local file and put some environment variables there (see below)
  3. Apply migrations
> crystal src/bin/cake.cr -- db:migrate

or install Cake and exec cake db:migrate

  1. Launch the server in development mode
> crystal src/bin/server.cr --progress

Example output:

Example terminal screenshot

Environment variables

Crystal World follows twelve-factor methodology and therefore relies on environment variables. You can see example and default variables at /.env.example file.

Testing

Crystal has a convenient testing environment built-in. Read more at Testing docs. Basically, you place specs under /spec folder and run them with crystal spec. It's also a good idea to have a separate /.env.test file.

Real World comes with integration testing suit, which can be found at https://github.com/gothinkster/realworld/tree/master/api. Crystal World uses this script in its CI, so if the badge is green it means that all the integration tests are passed. You can run these tests locally on your machine as well, just to be sure.

Contributors

Licensing

This software is licensed under MIT License.

Open Source Initiative

More Repositories

1

unity-wakatime

WakaTime plugin for Unity ⏱
C#
116
star
2

migrate.cr

A database migration solution 🚜
Crystal
31
star
3

i18n.cr

Internationalization shard 🌍
Crystal
24
star
4

jbuilder-json_api

Jbuilder meets jsonapi.org specifications
Ruby
23
star
5

http-multiserver.cr

Mount multiple web applications 🚦
Crystal
23
star
6

http-params-serializable

The HTTP params parsing module for Crystal 🤓
Crystal
20
star
7

tarantool.cr

The Tarantool driver (a.k.a. connector) 🕷
Crystal
19
star
8

mini_redis

A light-weight low-level Redis client for Crystal ♨️
Crystal
18
star
9

validations.cr

Validations module for Crystal ✅
Crystal
13
star
10

tele.cr

A convenient Telegram Bot framework 🤖
Crystal
13
star
11

callbacks.cr

Expressive callbacks module for Crystal 🚉
Crystal
12
star
12

background

Fast background job processing
Crystal
11
star
13

stripe.cr

🚧 WIP 🚧 Stripe API wrapper 💳
Crystal
7
star
14

onyx-http-deprecated

Deprecated Onyx module
Crystal
6
star
15

cake-bake

Bake Cakefile into native Crystal code 🍞
Crystal
5
star
16

time-span-humanize

Time::Span#humanize method
Crystal
5
star
17

crack

Alternative Crystal HTTP server implementation
Crystal
5
star
18

timer.cr

A versatile timer module ⏲
Crystal
4
star
19

realworld-benchmark

RealWorld Benchmark
Crystal
3
star
20

onyx-40-loc-distributed-chat

Distributed websocket chat in 40 lines of code
JavaScript
2
star
21

time_format.cr

Time spans formatting made simple ⌚️
Crystal
2
star
22

Expense-Manager-2

Java
1
star
23

tele-broadcast.cr

Broadcasting for Tele 📢
Crystal
1
star
24

attribute_enum

Rails-like enums with ease
Ruby
1
star