An open API service indexing awesome lists of open source software.

https://github.com/github30/webdavjson

WebDAVJSON is a simple server-side script (PHP or Node.js) that gives you REST-style file management: list, upload, delete, download, all via JSON. Supports CORS, optional API key authentication, and file extension filtering.
https://github.com/github30/webdavjson

cors javascript mkcert nodejs php php7 php8 webdav webdav-server webdavjson windows

Last synced: 3 months ago
JSON representation

WebDAVJSON is a simple server-side script (PHP or Node.js) that gives you REST-style file management: list, upload, delete, download, all via JSON. Supports CORS, optional API key authentication, and file extension filtering.

Awesome Lists containing this project

README

          

[![PHP Tests](https://github.com/GitHub30/WebDAVJSON/actions/workflows/php-test.yml/badge.svg?branch=main)](https://github.com/GitHub30/WebDAVJSON/actions/workflows/php-test.yml)
[![Node.js Tests](https://github.com/GitHub30/WebDAVJSON/actions/workflows/nodejs-test.yml/badge.svg?branch=main)](https://github.com/GitHub30/WebDAVJSON/actions/workflows/nodejs-test.yml)

# WebDAVJSON

WebDAVJSON is a simple PHP/Node.js script that provides file management APIs. It supports CORS, optional API key authentication, upload with extension restrictions, and JSON response for file listing.

## Features
- CORS support
- Optional API key authentication
- File listing (JSON)
- File upload, download, and delete
- Extension restrictions
- Single-file program

## Windows Setup

```powershell
winget install mkcert Node.js --silent
mkcert -install
mkcert localhost
node index.mjs
# await fetch('https://localhost:8443/').then(r=>r.json())
# await fetch('https://localhost:8443/?filename=foo.txt', {method: 'PUT', body: 'foobar'})
```

## Linux Setup

```bash
wget https://raw.githubusercontent.com/GitHub30/WebDAVJSON/refs/heads/main/index.php
```

## API Endpoints

| Method | Path | Description |
|----------|-----------------------------|-------------------------|
| GET | /?filename=abc.txt | Download file |
| GET | / | List files (JSON) |
| POST/PUT | / | Upload file |
| POST/PUT | /?filename=abc.txt | Binary upload |
| DELETE | /?filename=abc.txt | Delete file |

## Usage Examples

### List files
```bash
curl http://localhost/
```

### Search files (partial match)
```bash
curl "http://localhost/?q=abc"
```

### Download file
```bash
curl -O http://localhost/?filename=abc.txt
```

### Download file (as attachment)
```bash
curl -OJ "http://localhost/?download&filename=abc.txt"
```

### Upload file (multipart/form-data)
```bash
curl -F "file=@abc.txt" http://localhost/
```

### Upload file (PUT, binary)
```bash
curl -X PUT --data-binary @abc.txt "http://localhost/?filename=abc.txt"
```

```javascript
const blob = await fetch($0.src).then(r=>r.blob())
await fetch('https://localhost:8443/?filename=image.png', {method: 'POST', body: blob})
```

### Delete file
```bash
curl -X DELETE "http://localhost/?filename=abc.txt"
```

## Authentication (API Key)
If you set a value for `$api_key` in `index.php`, the header `Authorization: Bearer ` is required.

Example:
```bash
curl -H "Authorization: Bearer your_api_key" http://localhost/
```

## Allowed Extensions
`txt, jpg, png, webp, heic, gif, pdf, docx, xlsx, zip, mp4, gz`

## License
MIT