An open API service indexing awesome lists of open source software.

https://github.com/pyozer/myexpress


https://github.com/pyozer/myexpress

Last synced: about 23 hours ago
JSON representation

Awesome Lists containing this project

README

          



## 🐼 Summary

- [Rules](#rules)
- [Overview](#overview)
- [Story](#story)
- [Credits](#credits)

## 🦊 Rules

Hi, here are some rules to carry out this story oav;

- You **MUST** create a git repository named `myExpress`
- You **MUST** create a file called `.author.json` with your username followed by a newline:

```sh
~/codeflix/onecode/myExpress ❯❯❯ cat -e .author.json
{
"username": "ch0pper"
}$
```

> Of course, you can talk about the subject with other developers, peer-learning is
> the key to be a better developer. Don't hesitate to ask questions or help people in
> the channel **izi-learning-network**

> Don't forget, there is no useless question :-)

## 🐱 Overview

The purpose of this challenge is to (re)create a HTTP client server.
You **HAVE TO** use TypeScript and the **http** node package

## 🐨 Story

#### From express to myExpress

The `express()` function is a top-level function exported by the express module.

```js
const express = require('./my-express')
const app = express()
```

You **HAVE TO** browse the real [express API](https://expressjs.com)

##### Basics

You **HAVE TO** and handle the following properties:

- `app.get()`
- `app.post()`
- `app.put()`
- `app.delete()`
- `app.all()`
- `app.listen()`

Exemple:

```js
app.get('/api', (req, res) => {
res.json({ hello: 'From API' })
})
```

#### Rendering

You **HAVE TO** add a render method that follow express rules:

```js
app.render('home', (err, html) => {
// ...
})

app.render('home', { name: 'Ch0pper' }, (err, html) => {
res.send(html)
})
```

The first parameters **HAVE TO** found an `html.mustache` file on a directory called pages.

What is **mustache** ? Well, it's your new handmade template engine, #braaaaaah :-)
When the second parameter is an object, you **MUST** replace all mustache template keys by their values ;

Exemple :

```html



Efrei




Hello {{name}}


```

Well, you will replace **name** by **Chopper**.

A sexy template thing is to add through a pipe (|) what we called a **modifier**.
You have to handle the following modifier:

- `upper`
- `lower`
- `fixed:n`

For the fixed example, you **HAVE TO** handle args separate by **:**.

Exemple:

```js
app.render('home', { name: 'Ch0pper', weight: 33.1337 }, (err, html) => {
// ...
})
```

```html



Efrei




Hello {{name | upper}}, my weight is {{weight | fixed:2 }}


```

> Weight displayed will be **33.13**

#### Advanced

##### Middleware

Now you **HAVE TO** handle the `app.use` method for middleware.
This method take a callback with the following signature:

```js
function (req, res, next) {
console.log('Time: %d', Date.now())
next()
}
```

> What is next ? ;)

##### Query parameters and args

Well, an API is better if we can handle all parameters send by the client.
You **HAVE TO** handle all of them ;D

```js
app.get('/user/:id', (req, res) => {
const { id } = req.params
console.log(`The user id is ${id}`)
// ...
})

app.get('/users?limit=42&status=ADMIN', (req, res) => {
const { limit, status } = req.qParams
console.log(`The limitation is ${limit} for ${status} users`)
// ...
})
```

## 🦄 Bonus

In bulk:

- Add mustache features like if/else, for-loop, etc.x1x
- Add more express to myExpress features

## 🐵 Credits

Craft with :heart: in **Paris**.