Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cyclic-software/cyclic-sdk
Cyclic.sh SDK to build APIs
https://github.com/cyclic-software/cyclic-sdk
cyclic npm sdk
Last synced: about 2 hours ago
JSON representation
Cyclic.sh SDK to build APIs
- Host: GitHub
- URL: https://github.com/cyclic-software/cyclic-sdk
- Owner: cyclic-software
- License: isc
- Created: 2021-08-04T14:38:01.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-08-23T11:16:14.000Z (about 3 years ago)
- Last Synced: 2024-10-05T14:48:04.419Z (about 1 month ago)
- Topics: cyclic, npm, sdk
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/@cyclic.sh/sdk
- Size: 890 KB
- Stars: 7
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @cyclic.sh/sdk
Cyclic api framework. Build vanilla javascript APIs without the headache.
## Quick Start
Run the following:
```sh
npm install @cyclic.sh/sdkecho "const sdk = require('@cyclic.sh/sdk')" >> server.js
mkdir api
echo "module.exports.all = async (req,res) => {
console.log(req.body)
res.set('Content-Type','application/json')
res.body = {headers: req.headers, params: req.params, env: process.env}
}" > api/index.js
npx cy
```
You now have a running API running on port 3000`curl -i -XGET http://localhost:3000`
## API Routes
Cyclic uses path based routing to find the right handler. Then resolves the handler method based on HTTP method.
```text
.
├── api
│ ├── index.js <- responds to: /
│ ├── pets.js <- responds to: /pets
│ └── pets
│ ├── index.js <- responds to: /pets/
│ └── :id.js <- responds to: /pets/${id}
├── package-lock.json
├── package.json
└── server.js
```## Handler Methods
Here is the logic cyclic uses to find a handler method:
```javascript
const method = req.method.toLowerCase();
let func = handler[method];
if (!func) {
if (handler.all) {
func = handler.all;
} else {
throw new Error(`Found handler but it is missing the requested method [${method}] or 'all'`);
}
}
```## Installing
`npm install @cyclic.sh/sdk`
## For those developing this module
### Building
`npm install`
### Publishing
```
npm version [feature|minor|patch]
git push
git push --tags
npm publish --access=public
```