-
Notifications
You must be signed in to change notification settings - Fork 222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add documentation of API (/w refactor of routes) #29
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FILE: api/teams.routes.js
This code includes error handling to catch any issues that may occur when reading the teams.json file, and it also uses an if statement to check whether the team was found before returning the JSON response. 😊
--------------------------------------
import { Hono } from 'hono'
import fs from 'fs'
const teamsApi = new Hono()
let teams
try {
teams = JSON.parse(fs.readFileSync('../db/teams.json', 'utf8'))
} catch (error) {
console.error(Error reading teams.json: ${error}
)
}
teamsApi.get('/', (ctx) => {
return ctx.json(teams)
})
teamsApi.get('/:id', (ctx) => {
const id = ctx.req.param('id')
const foundTeam = teams.find((team) => team.id === id)
if (!foundTeam) {
return ctx.json({ message: 'Team not found' }, 404)
}
return ctx.json(foundTeam)
})
export { teamsApi }
FILE: Implementacióne:
Tienes el codigo debajo por si quieres implementarlo en otro commit ❤️ ` const presidentApi = new Hono() try { /**
/**
if (!foundPresident) { return ctx.json(foundPresident) export { presidentApi } |
No puedo usar los paquetes de node porque sino el wrangler no me arranca, pero sí que he añadido la doc al resto de endpoints. Gracias! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job buddy!
Creation an API documentation of kings league, contains all endpoints from other contributions
It's the first version and It's only visible opening the file 'index.html'
Pending:
doc:api
command to generate API dochost
to set dynamically on generate site