A RESTful API service allowing users to create, retrieve, update, delete, and convert various data fragments. The service handles multiple content types including text, HTML, Markdown, JSON, and images with fine-grained access control.
- Create & Manage Fragments: Store and manage pieces of data with appropriate metadata
- Content Type Support: Handles multiple formats including:
- Text formats:
text/plain,text/markdown,text/html,text/csv - Data formats:
application/json,application/yaml - Image formats:
image/png,image/jpeg,image/webp,image/avif,image/gif
- Text formats:
- Format Conversion: Convert between compatible formats (e.g., Markdown to HTML, CSV to JSON)
- Authentication: Secure API endpoints with HTTP Basic Auth & AWS Cognito
- Data Persistence: Store fragment data and metadata
- Comprehensive Testing: High test coverage (>94%) ensuring reliability
- Node.js (Latest LTS version recommended)
- npm (comes with Node.js)
-
Clone the repository:
git clone https://github.com/your-username/fragments.git cd fragments -
Install dependencies:
npm install
-
Configure environment variables (create a .env file):
PORT=8080 LOG_LEVEL=info API_URL=http://localhost:8080 HTPASSWD_FILE=./user.htpasswd # Add AWS credentials if using AWS services
-
Development Mode:
npm run dev
Runs the server with auto-reload, debug logging, and file watching
-
Debug Mode:
npm run debug
Runs with Node.js inspector enabled on port 9229 for attaching a debugger
-
Production Mode:
npm start
Runs the server in production mode
-
Build:
npm run build
Compiles TypeScript files to JavaScript
-
Lint:
npm run lint
Runs ESLint to check code style and potential errors
-
Test:
npm testRuns the test suite
-
Coverage:
npm run coverage
Generates test coverage reports
All endpoints require authentication using either HTTP Basic Auth or AWS Cognito tokens.
GET /v1/fragments- List all fragments for the authenticated userPOST /v1/fragments- Create a new fragmentGET /v1/fragments/:id- Get a specific fragment by IDPUT /v1/fragments/:id- Update a specific fragmentDELETE /v1/fragments/:id- Delete a specific fragmentGET /v1/fragments/:id/info- Get metadata about a specific fragmentGET /v1/fragments/:id.:ext- Get a fragment converted to a different format
PORT- Server port (default: 8080)LOG_LEVEL- Logging level (default: 'info', can be set to 'debug')API_URL- Base URL for the APIHTPASSWD_FILE- Path to the.htpasswdfile for HTTP Basic AuthAWS_COGNITO_POOL_ID- AWS Cognito User Pool IDAWS_COGNITO_CLIENT_ID- AWS Cognito Client App IDNODE_ENV- Node environment (e.g., 'development', 'production')
fragments/
├── src/
│ ├── app.ts # Express app setup
│ ├── auth/ # Authentication middleware
│ ├── model/ # Data models
│ │ ├── data/ # Data storage abstraction
│ │ │ └── memory/ # In-memory implementation
│ │ └── fragment.ts # Fragment model
│ ├── routes/ # API route handlers
│ │ └── api/ # API endpoints
│ └── utils/ # Utility functions
│ ├── converter.ts # Format conversion
│ └── formatValidator.ts # Content validation
└── tests/ # Test files
This project includes VS Code settings for:
- Auto-formatting on save using Prettier
- 2-space indentation
- ESLint integration
- Debug configuration
To use the debugger in VS Code:
- Open the Debug view (
Cmd+Shift+D) - Select "Debug via npm run debug" from the dropdown
- Press F5 to start debugging
- Made with 🧡 for DPS955 - Cloud Computing.
- Special thanks to @humphd