Koa.js Form Data - Koa.js

What are Koa Forms?

Forms play an important part of web. Forms are offered by almost all the websites which fetch some information. Koa-body need to be installed to start with Koa forms. Koa-body is installed by:

The content of the file app.js need to be replaced with the code:

By the above code, body Parser and Multer are imported. Body parser is used for parsing requests of json and x-www-form-urlencoded and Multer is used for parsing multipart/form-data.

A html form is created to test. Initially a new view form.pug is created by:

Server runs by:

Fill the form as desired in the localhost:3000/ and the response appears as:

submission form

Body of the request appears as JavaScript object on the console. For instance,

Console output for form

Request body object contains the parsed request body. The fields from the object can be used similar to that of normal JS objects.

There are many other ways to send a request but all the requests are handled in the same way as above by koa. More information about different ways of making request is available in this page .

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Koa.js Topics