VoidDevsorg / cloudflare-workers-hono-api

This repository contains a Restful API script developed using Cloudflare Workers and Hono.dev.

Home Page:https://hono.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cloudflare Workers Hono API Script



Getting Started

To use this script, follow these steps:

  • Create a Cloudflare Account:

  • Enable Cloudflare Workers:

    • You may need to enable Cloudflare Workers for your account. Once enabled, you can access the Workers section.
  • Create a Worker Script:

    • Go to the Cloudflare Workers interface.
    • Create a new Worker and give it a name.
  • Activate the Worker:

    • When your Worker script is ready, activate it and assign it to the desired domain names.


  • Download Required Packages:
npm i -g wrangler
# then
npm i
  • Update the wrangler.toml Configuration File:
name = "<YOUR-WORKERS-NAME>"

Replace <YOUR-WORKERS-NAME> in name = "<>" with your chosen worker's name.

  • Run the Template:
npm run dev
  • Deploy Your Worker to Cloudflare Workers:
npm run deploy


Example Usage

app.get('/user/:id', async (c) => {
    const { id } = c.req.param();
    c.header('Content-Type', 'application/json');

    return c.json({
        id
    });
});


License

MIT License

Copyright (c) 2023 Void Development

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

About

This repository contains a Restful API script developed using Cloudflare Workers and Hono.dev.

https://hono.dev

License:MIT License


Languages

Language:TypeScript 100.0%