---
title: "Your first route"
description: "There are 3 types of paths in Elysia. static paths, dynamic paths, and wildcards. Learn how to use them to create your first route."
url: "https://next.elysiajs.com/tutorial/getting-started/your-first-route/"
---

# Your first route

When we enter a website, it takes

1. **path** like `/`, `/about`, or `/contact`
2. **method** like `GET`, `POST`, or `DELETE`

To determine which resource to show, simply called **“route”**.

In Elysia, we can define a route by:

1. Call method named after HTTP method
2. Path being the first argument
3. Handler being the second argument

```typescript
import { Elysia } from 'elysia'

new Elysia()
  .get('/', 'Hello World!')
  .listen(3000)
```

## Routing

Path in Elysia can be grouped into 3 types:

1. static paths - static string to locate the resource
2. dynamic paths - segment can be any value
3. wildcards - path until a specific point can be anything

See [Route](/essential/route/).

## Static path

Static path is a hardcoded string to locate the resource on the server.

```ts
import { Elysia } from 'elysia'

new Elysia()
  .get('/hello', 'hello')
  .get('/hi', 'hi')
  .listen(3000)
```

See [Static path](/essential/route/#static-path).

## Dynamic path

Dynamic paths match some part and capture the value to extract extra information.

To define a dynamic path, we can use a colon `:` followed by a name.

```typescript
import { Elysia } from 'elysia'

new Elysia()
    .get('/id/:id', ({ params: { id } }) => id)
    .listen(3000)
```

Here, a dynamic path is created with `/id/:id`, which tells Elysia to capture the value `:id` segment with value like **/id/1**, **/id/123**, **/id/anything**.

<!--astro:end-->

See [Dynamic path](/essential/route/#dynamic-path).

### Optional path parameters

We can make a path parameter optional by adding a question mark `?` after the parameter name.

```typescript
import { Elysia } from 'elysia'

new Elysia()
    .get('/id/:id?', ({ params: { id } }) => `id ${id}`)
    .listen(3000)
```

<!--astro:end-->

See [Optional path parameters](/essential/route/#optional-params).

## Wildcards

Dynamic paths allow capturing a single segment while wildcards allow capturing the rest of the path.

To define a wildcard, we can use an asterisk `*`.

```typescript
import { Elysia } from 'elysia'

new Elysia()
    .get('/id/*', ({ params }) => params['*'])
    .listen(3000)
```

<!--astro:end-->

See [Wildcards](/essential/route/#wildcard).

## Assignment

Let’s recap, and create 3 paths with different types:
