Cloudflare worker
Cloudflare Workers provides a serverless execution environment that allows you to create entirely new applications or augment existing ones without configuring or maintaining infrastructure.
Documentation for Cloudflare worker.
Cloudflare-worker-request-data
Getting data from Cloudflare-worker requests is not as easy as you were working with Express.js on Nodejs, it is necessary to understand the organization of request in Cloudflare-worker.
Cloudflare-worker-request-data is a JavaScript package released under MIT license, which can help you with getting data from a GET or POST request. With this package, it is not necessary to study the API of request from documentation file, and the usage is quite simple and straightforward.
Installation
npm i cloudflare-worker-request-data
Example
import { RequestData } from 'cloudflare-worker-request-data';
export default {
    async fetch(request, env, ctx) {
        const data = await RequestData(request)
        // do something with the data           
    }
};
Description
RequestData(request) in the above example can get return of
- a Stringin case of "application/text" or "text/html"
- a Objectin case of "application/json", "application/x-www-form-urlencoded", "mutipart/form-data"
- a Stringwhich is empty if nothing parsed
- The request shall be either in GETorPOST, other methods of request will directly return you with an emptyString.
 

 
    
Top comments (0)