Phriction Knowledge Center - Hexavara Technology Crema Framework Router and Endpoints History Version 2 vs 3
Version 2 vs 3
Version 2 vs 3
Content Changes
Content Changes
[COMING SOON]
The router component provides us a way to define routes that are mapped to handlers that process the request. Crema uses [[ https://github.com/gorilla/mux | Gorilla Mux ]]-based HTTP router and it works almost the same way.
Crema uses method **server.AddRoutes()** to register new endpoints. The method requires three parameters:
- HTTP Method
- URL
- Handler Function
Let's start writing a sample endpoint:
```
server.AddRoutes(http.MethodGet, "/hello", helloHandler)
```
From the example above, we register a route mapping an URL path “**///hello//**” to a handler “**//helloHandler//**” which is requested using **//HTTP GET//**.
Like Gorilla Mux, paths can have variables too. The variables are defined using the format **//{var}//**. For example:
```
server.AddRoutes(http.MethodGet, “/users/{id}”, userHandler)
server.AddRoutes(http.MethodGet, “/users/{name}”, userHandler)
```
[COMING SOON]The router component provides us a way to define routes that are mapped to handlers that process the request. Crema uses [[ https://github.com/gorilla/mux | Gorilla Mux ]]-based HTTP router and it works almost the same way.
Crema uses method **server.AddRoutes()** to register new endpoints. The method requires three parameters:
- HTTP Method
- URL
- Handler Function
Let's start writing a sample endpoint:
```
server.AddRoutes(http.MethodGet, "/hello", helloHandler)
```
From the example above, we register a route mapping an URL path “**///hello//**” to a handler “**//helloHandler//**” which is requested using **//HTTP GET//**.
Like Gorilla Mux, paths can have variables too. The variables are defined using the format **//{var}//**. For example:
```
server.AddRoutes(http.MethodGet, “/users/{id}”, userHandler)
server.AddRoutes(http.MethodGet, “/users/{name}”, userHandler)
```