Well, I use Fastify most times for APIs and it has a nice method called inject, which is mostly just used for testing. The setup ends up looking something like
inject
// server.js const Fastify = require('fastify'); const app = Fastify(); app.get('/some-route', async () => "data"); app.listen(3000, err => { if(err) { console.error(err); process.exit(); } console.log('listening'); }); module.exports = app; // main.test.js const test = require('ava'); const app = require('../server.js'); test('API Testing', async t => { await app.inject({ url: '/some-route' }) .then(res => { t.is(res.statusCode, 200); }) .catch(err => t.fail()); }); });
(note: roughed most of this from memory so it might not be 100% runnable).
Most people use something like Postman. I've switched over to the Insomnia REST client.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Tests
Well, I use Fastify most times for APIs and it has a nice method called
inject
, which is mostly just used for testing. The setup ends up looking something like(note: roughed most of this from memory so it might not be 100% runnable).
Otherwise
Most people use something like Postman. I've switched over to the Insomnia REST client.