<commit_before>---
layout: post
title: NYNY 3.2 - a micro web framework meets the Rails' router
category: posts
---

_Summary_: [New York, New York][nyny] 3.2 uses the Rails' router.

As a web developer that writes in Rails, I got a lot of interests in the
internals of web frameworks. Rails, however, is pretty big, and a person can
get lost in its source code.

So I decided that I should make a small web framework myself, and half a year
ago I released "New York, New York", which I positioned as a small Sinatra
clone at that time.

Time has passed, and I spend all my free coding resources to hack on NYNY and
to experiment with it. During this period I also started using NYNY to prototype
any ideas I had for web apps. It did well as a framework, and I never
stopped using it.

However, I was missing something. I was missing Rails' routing. But I was not
ready to implement something similar myself, because that would violate one
of the primary goals of NYNY - being simple and obvious. And then I met
[Journey][journey] - the Rails' router.

What seemed a crazy idea at the time, now has become a reality. NYNY 3.2 uses
Journey for routing. Defaults, constraints, splats and all the syntax you are
used to is available in NYNY (in a much simple form):

You can use any construct or convention [supported in Rails][bound-params]
for the path string:

```ruby
class App < NYNY::App
  get '/:foo(/:bar)' do
    'Hello World!'
  end
end
```

You can use [the same constraints][constraints] you use in Rails:

```ruby
class App < NYNY::App
  get '/', :constraints => {:format => :html} do
    'html'
  end
end
```

And same defaults:

```ruby
class App < NYNY::App<commit_msg>Improve post<commit_after>---
layout: post
title: NYNY 3.2 - a micro web framework meets the Rails' router
category: posts
---

_Summary_: [New York, New York][nyny] 3.2 uses the Rails' router.

As a web developer that writes in Rails, I got a lot of interests in the
internals of web frameworks. Rails, however, is pretty big, and a person can
get lost in its source code.

So I decided that I should make a small web framework myself, and half a year
ago I released "New York, New York", which I positioned as a small Sinatra
clone at that time.

Time has passed, and I spend all my free coding resources to hack on NYNY and
to experiment with it. During this period I also started using NYNY to prototype
any ideas I had for web apps. It did well as a framework, and I never
stopped using it.

However, I was missing something. I was missing Rails' routing. But I was not
ready to implement something similar myself, because that would violate one
of the primary goals of NYNY - being simple and obvious. And then I met
[Journey][journey] - the Rails' router.

What seemed a crazy idea at the time, now has become a reality. NYNY 3.2 uses
Journey for routing. Defaults, constraints, splats and all the syntax you are
used to is available in NYNY (in a much simple form):

You can use any construct or convention [supported in Rails][bound-params]
for the path string:

```ruby
class App < NYNY::App
  get '/:foo(/:bar)' do
    "Hello #{params[:foo]} #{params[:bar]}!"
  end
end
```

You can use [the same constraints][constraints] you use in Rails:

```ruby
class App < NYNY::App
  get '/', :constraints => {:format => :html} do
    'html'
  end
end
```

And same defaults:

```ruby
class App < NYNY::App
{'fraction_non_alphanumeric': 0.0778990852758926, 'fraction_numerical': 0.0035408675125405725, 'mean_word_length': 3.8497854077253217, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '351812', 'n_tokens_mistral': 1011, 'n_tokens_neox': 959, 'n_words': 561}