Skip to content

$ npm i zely@latest
$ npm i zely@latest

v1.0 has been released. 🎉

Compared to v0 and v1, many features have been added. In this post, I will introduce what has changed and how to migrate from v0 to v1.

Major Changes ​

I'll start by talking about the major changes.

Return ​

In this update, we thought about how users can use zely more easily and simply.

We found that printing a simple hello world required a lot of code.

ts
export function get(req, res) {
  res.send('hello world');
}
export function get(req, res) {
  res.send('hello world');
}

Now all you have to do is return.

ts
export function get() {
  return 'hello world';
}
export function get() {
  return 'hello world';
}

However, the code you just showed is also longer than expected. So let's work some magic to make it shorter. 🔮

Methods ​

You can now response to requests simpler.

ts
export default {
  message: 'hello',
};
export default {
  message: 'hello',
};

But just export default {} responds to all requests. If you want to run only when the method is post:

ts
import { GET } from 'zely/methods';

export default GET({
  /* data */
});
import { GET } from 'zely/methods';

export default GET({
  /* data */
});

Check out the guide/methods for more details

Migrate from v0 ​

Code written in v0 will work in v1 without any special code modifications.
But let's replace the v0 code with the v1 style.

ts
import { GET } from 'zely/methods';

export default GET({
  message: 'hello world',
});
import { GET } from 'zely/methods';

export default GET({
  message: 'hello world',
});
ts
export function get(req, res) {
  res.send({ message: 'hello world' });
}
export function get(req, res) {
  res.send({ message: 'hello world' });
}