This is for questions regarding the Kemal framework for the Crystal language.
Questions tagged [kemal]
34 questions
6
votes
1 answer
How to free memory allocated for some structure in Crystal - manually?
I have a Kemal-based RESTful web service that returns "very big" (from 10 to 17M in size) chunks of JSON data, which is produced by to_json method from the "big" Hash structure.
According to GC warning messages my code "may lead to memory leaks"…

drvtiny
- 705
- 3
- 13
6
votes
2 answers
Starting crystal in production mode
I've been running my Crystal webapp by building it, and then running the executable. However, it always listens on port 3000.
How do I build/run Crystal webapps listening on 80 and 443?
I'm using Kemal as well. Here is my sample app.
require…

Tyler
- 19,113
- 19
- 94
- 151
5
votes
1 answer
Cycling between Fibers with no IO
As far as I know, crystal cycles Fibers with io, meaning that if one fiber is waiting for io, crystal will switch to an another fiber.
What if we spawn two fibers but one of them does constant computation/loop with no io?
For example, with the code…

Oguz Bilgic
- 3,392
- 5
- 36
- 59
4
votes
2 answers
Using Crystal/Kemal to listen for UDP packets
I have been trying to create a non-blocking server using Crystal and Kemal which will (a) listen for a stream of UDP messages being sent to it, and (b) then forwarding that message to a WebSocket to any browsers who have started a ws connection.
So…

CyberFerret
- 275
- 3
- 8
3
votes
2 answers
Crystal build fails with "ld: library not found for -lssl"
I've just started a brand new Crystal app, added Kemal, and when building the "Hello World!" app from the Kemal documentation, I get:
$ crystal build --release src/orderprinterlinks.cr
ld: library not found for -lssl
clang: error: linker command…

Bjorn Forsberg
- 470
- 1
- 6
- 19
3
votes
1 answer
Using Kemal-sessions with websocket
The documentation for the kemal-session module for the Kemal web framework in Crystal provides this example:
require "kemal"
require "kemal-session"
get "/set" do |env|
env.session.int("number", rand(100)) # set the value of "number"
"Random…

Clement J.
- 3,012
- 26
- 29
2
votes
1 answer
View metrics or more insights on HTTP::Server
We're running a production system on Crystal/Kemal. The calling service sees quite often a Connection refused error. I was wondering how can I see more insights/metrics into a running instance of HTTP::Server/Kemal. I'm referring to the number of…

linkyndy
- 17,038
- 20
- 114
- 194
2
votes
1 answer
Kemal configuration using blocks
Kemal currently allows setting configuration options via:
Kemal.config.env = "development"
Kemal.config.port = "3456"
I want to do something like with a block:
configuration do |config|
config.env = "development"
config.port = "3456"
…

lewis
- 131
- 1
- 9
2
votes
1 answer
Crystal lang fiber and web socket
I'm beginner in crystal.
I have question, maybe somebody can help me.
I use Kemal framework.
Have this code:
require "kemal"
require "json"
channel = Channel(Card).new
post "/posts" do |env|
json = JSON.parse(env.request.body as String)
url =…

schumi
- 21
- 3
1
vote
1 answer
Parsing JSON as Array(String) in Kemal
I want to create an endpoint that receives JSON data and should parse it as an array of strings.
POST /
{
"keys": ["foo", "bar"]
}
I'm running into problems with the type system. This is what I tried (.as(Array(String))) but it does not…

Philipp Claßen
- 41,306
- 31
- 146
- 239
1
vote
1 answer
Slow exception report in Kemal
I use crystal 32.1 and Kemal. In case I have runtime exception it take 21 seconds to print backtrace. Any idea why it take so long?
500 GET /chats/by_sale/1 21280.52ms
Backtrace:
web_1 | I, [2020-02-07 17:57:33 +00:00 #1] INFO -- : [1]
web_1 …

Sergey Makridenkov
- 624
- 6
- 14
1
vote
1 answer
How do you access the return value of the route in Kemal after_all method?
From the after_all handler in a Kemal file, how do I modify the response from the route?
[See example below]
VERSION = "0.1.0"
require "kemal"
# Configure kemal parameters
serve_static false
get "/" do
"Hello world!"
end
after_all do |env|
#…

Oeste
- 1,041
- 2
- 7
- 13
1
vote
1 answer
How to process html form data with kemal and crystal
I want to get user input in an html form and use the data to populate a database table. Sinatra returns the form data in a hash, params. Can I do this with Kemal and Crystal?
Please note, I am in the process of learning Crystal, so this may not even…

lewis
- 131
- 1
- 9
1
vote
1 answer
Kemal caching responses with handler middleware
Kemal caching responses with handler middleware
I'm trying to do caching of some GET request with Kemal.
class CachingHandler < Kemal::Handler
property cache : Hash(String, IO::Memory)
def initialize
@cache = Hash(String,…

Javier Valencia
- 697
- 7
- 24
1
vote
1 answer
Get JSON in POST in kemal
What I want is a POST request in kemal where the body has a certain number of keys/values that I want to access and then an arbitrary JSON Object that I just want to stringify and pass on and later parse back to JSON.
My problem is that I apparently…

tpei
- 671
- 9
- 26