|  | 
| 4 | 4 |   </a> | 
| 5 | 5 | </p> | 
| 6 | 6 | 
 | 
| 7 |  | -# @helia/delegated-routing-v1-http-api-server <!-- omit in toc --> | 
| 8 |  | - | 
| 9 | 7 | [](https://ipfs.tech) | 
| 10 | 8 | [](https://discuss.ipfs.tech) | 
| 11 | 9 | [](https://codecov.io/gh/ipfs/helia-delegated-routing-v1-http-api) | 
| 12 | 10 | [](https://github.com/ipfs/helia-delegated-routing-v1-http-api/actions/workflows/js-test-and-release.yml?query=branch%3Amain) | 
| 13 | 11 | 
 | 
| 14 | 12 | > A Delegated Routing V1 HTTP API server powered by Helia | 
| 15 | 13 | 
 | 
| 16 |  | -A server implementation of the IPFS [Delegated Routing V1 HTTP API](https://specs.ipfs.tech/routing/http-routing-v1/). | 
|  | 14 | +## About | 
|  | 15 | + | 
|  | 16 | +Implements HTTP routes for a Fastify server that conform to the [Routing V1 HTTP API](https://specs.ipfs.tech/routing/http-routing-v1/). | 
|  | 17 | + | 
|  | 18 | +### Example | 
|  | 19 | + | 
|  | 20 | +```typescript | 
|  | 21 | +import { createHelia } from 'helia' | 
|  | 22 | +import { createRoutingV1HttpApiServer } from '@helia/routing-v1-http-api-server' | 
|  | 23 | + | 
|  | 24 | +const helia = await createHelia() | 
|  | 25 | +const server = await createRoutingV1HttpApiServer(helia, { | 
|  | 26 | +  listen: { | 
|  | 27 | +    // fastify listen options | 
|  | 28 | +  } | 
|  | 29 | +}) | 
|  | 30 | + | 
|  | 31 | +// now make http requests | 
|  | 32 | +``` | 
|  | 33 | + | 
|  | 34 | +Alternatively if you have a Fastify instance already you can add routes to it. | 
|  | 35 | +, | 
|  | 36 | + | 
|  | 37 | +### Example | 
|  | 38 | + | 
|  | 39 | +```typescript | 
|  | 40 | +import fastify from 'fastify' | 
|  | 41 | +import cors from '@fastify/cors' | 
|  | 42 | +import { createHelia } from 'helia' | 
|  | 43 | +import routes from '@helia/routing-v1-http-api-server/routes' | 
|  | 44 | + | 
|  | 45 | +const server = fastify({ | 
|  | 46 | + // fastify options | 
|  | 47 | +}) | 
|  | 48 | +await server.register(cors, { | 
|  | 49 | +  origin: '*', | 
|  | 50 | +  methods: ['GET', 'OPTIONS'], | 
|  | 51 | +  strictPreflight: false | 
|  | 52 | +}) | 
| 17 | 53 | 
 | 
| 18 |  | -## Table of contents <!-- omit in toc --> | 
|  | 54 | +const helia = await createHelia() | 
| 19 | 55 | 
 | 
| 20 |  | -- [Install](#install) | 
| 21 |  | -- [API Docs](#api-docs) | 
| 22 |  | -- [License](#license) | 
| 23 |  | -- [Contribute](#contribute) | 
|  | 56 | +// configure Routing V1 HTTP API routes | 
|  | 57 | +routes(server, helia) | 
|  | 58 | + | 
|  | 59 | +await server.listen({ | 
|  | 60 | +  // fastify listen options | 
|  | 61 | +}) | 
|  | 62 | + | 
|  | 63 | +// now make http requests | 
|  | 64 | +``` | 
| 24 | 65 | 
 | 
| 25 | 66 | ## Install | 
| 26 | 67 | 
 | 
|  | 
0 commit comments