Escribe para buscar…

API

Build a REST API with Hono, handle routes and path parameters, and connect to a Turso database

Esta página todavía no se ha traducido — se muestra en su idioma original:English

Introduction

A web server can be configured as a resource server accessed through a set of “external” functions or endpoints (API).

REST is a fairly common way of interacting between client applications and services using HTTP.

An HTTP request consists of a method and a “path”.

By default, browsers use the GET method, and when you navigate to a website you do so with a GET request and only need to specify the “path”.

But a web API uses other methods, and clients use these methods to perform actions other than obtaining resources.

Work Environment

Create an application (with the netlify template) as explained at HTML page.

Modify the index.ts file to return a JSON document at the path /api/hello.

ts
app.get('/api/hello', (c) => {
  return c.json({
    ok: true,
    message: 'Hello Hono!',
  })
})

Run the server in development mode:

shell
netlify dev

Install curlie:

shell
scoop install curlie

Make a GET request:

shell
curlie localhost:8888/api/hello

Estás leyendo una vista previa.

Inicia sesión para leer el artículo completo. Cualquier cuenta abre 4 artículos gratuitos al mes; el alumnado y el profesorado leen las páginas de su curso sin límite.

Iniciar sesión