Algobreath API is a RESTful API built with TypeScript and the Hono framework, utilizing Drizzle ORM for database interactions with SQLite. It manages notes and tags with a many-to-many relationship.
- Notes Management: Create, read, update, and delete notes.
- Tags Management: Create, read, update, and delete tags.
- Relationship Handling: Associate tags with notes.
- Authentication: Secured with Bearer Token authentication.
- Framework: Hono
- ORM: Drizzle ORM
- Database: SQLite via Cloudflare Workers D1
- Language: TypeScript
- Node.js v16 or higher
- npm
- Wrangler CLI for deploying to Cloudflare Workers
-
Clone the repository
git clone https://github.com/yourusername/algobreath-api.git cd algobreath-api
-
Install dependencies
npm install
-
Configure Environment Variables
Create a
wrangler.toml
file with your Cloudflare Workers D1 database credentials. -
Run Migrations
Generate and apply database migrations:
npm run migrations:gen npm run migrations:apply
Start the development server with hot-reloading:
npm run dev
The API will be available at http://localhost:8787
.
Deploy the API to Cloudflare Workers:
npm run deploy
All endpoints are secured with Bearer Token authentication. Include the token in the Authorization
header:
Authorization: Bearer YOUR_TOKEN_HERE
-
GET /notes
Retrieve all notes.
-
POST /notes
Create a new note.
{ "slug": "unique-slug", "title": "Note Title", "markdown": "Note content in markdown." }
-
PUT /notes
Update an existing note.
{ "id": 1, "slug": "updated-slug", "title": "Updated Title", "markdown": "Updated content." }
-
GET /notes/latest
Retrieve the latest updated note.
-
GET /notes/:slug
Retrieve a note by its slug.
-
DELETE /notes/:id
Delete a note by its ID.
-
GET /tags
Retrieve all tags.
-
POST /tags
Create a new tag.
{ "slug": "unique-tag-slug", "title": "Tag Title" }
-
PUT /tags
Update an existing tag.
{ "id": 1, "slug": "updated-tag-slug", "title": "Updated Tag Title" }
-
GET /tags/:slug
Retrieve a tag by its slug.
-
DELETE /tags/:id
Delete a tag by its ID.
-
POST /notesToTags
Associate a tag with a note.
{ "noteId": 1, "tagId": "2" }
-
GET /notesToTags/notes/:noteId
Retrieve all tag IDs associated with a note.
-
GET /notesToTags/tags/:tagId
Retrieve all notes associated with a tag.
-
DELETE /notesToTags/:noteId/:tagId
Remove the association between a note and a tag.
-
notes
id
(integer, primary key, auto-increment)slug
(text, unique, not null)title
(text, not null)markdown
(text, not null)createdAt
(integer, not null)updatedAt
(integer, not null)
-
tags
id
(integer, primary key, auto-increment)slug
(text, unique, not null)title
(text, not null)
-
notes_to_tags
note_id
(integer, not null, foreign key tonotes.id
)tag_id
(integer, not null, foreign key totags.id
)- Primary Key: (
note_id
,tag_id
)
-
Install Dependencies
npm install
-
Run Development Server
npm run dev
-
Deploy to Cloudflare Workers
npm run deploy
-
Generate Migrations
npm run migrations:gen
-
Apply Migrations Locally
npm run local:migrations:apply
-
Apply Migrations to Production
npm run migrations:apply
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
This project is licensed under the MIT License.