# Build Web APIs with Aqueduct #2

In this second part we will look at **routing** in further detail by building an endpoint performing **CRUD**(*create, read, update, delete*) operations. We will make use of the `Router` and `Controller` classes in the handling of requests made to our endpoint.

%[https://www.youtube.com/watch?v=K4EqGjMjCY0] 

## **What is a Router?**

Routers capture the request by path and forwards it to a `Controller` using a `link` method for resolution or a `linkFunction` to implement middleware functionality to handle the request.

Here’s what it looks like:

```dart
final router = Router();

router.route('/path-1').link(() => Path1Controller());
router.route('/path-2').linkFunction((Request req) async {
  return Response.ok('Hello, World!');
});
```

The path is passed as an argument when `route()` is invoked, and can also accept route parameters:

```dart
router.route('/path-1/:name').link(...);
router.route('/path-2/[:name]').linkFunction(...); // wrapping in square brackets means its optional
```

So with this snippet whatever is passed in the path segment after `/path-1/` is captured in `name` path variable:

```dart
router.route('/path-1/:name').linkFunction((request) async {
  final name = request.path.variables['name'];
  return Response.ok('Hello, $name');
});
```

See how routers and controllers work in the [**video**](http://bit.ly/aqueduct-tutorial-2).

[Get the source code](https://github.com/graphicbeacon/aqueduct-tutorial/tree/part-2)

## **Further reading**

* [**Handling HTTP Requests**: Overview](http://aqueduct.io/docs/http/)
    
* [**Free Dart screencasts on Egghead.io**](https://egghead.io/instructors/jermaine-oppong)
