Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/davidesantangelo/datoji
A tiny JSON storage service. Create, Read, Update, Delete and Search JSON data.
https://github.com/davidesantangelo/datoji
api fastjson json json-api postgresql rack-attack rails redis rest-api ruby storage
Last synced: 3 months ago
JSON representation
A tiny JSON storage service. Create, Read, Update, Delete and Search JSON data.
- Host: GitHub
- URL: https://github.com/davidesantangelo/datoji
- Owner: davidesantangelo
- License: mit
- Created: 2020-06-10T13:47:23.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-19T19:25:31.000Z (almost 2 years ago)
- Last Synced: 2024-06-03T18:58:53.851Z (5 months ago)
- Topics: api, fastjson, json, json-api, postgresql, rack-attack, rails, redis, rest-api, ruby, storage
- Language: Ruby
- Homepage:
- Size: 1.5 MB
- Stars: 225
- Watchers: 12
- Forks: 6
- Open Issues: 30
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# DatoJi
A FREE RESTful HTTP based JSON API. It lets you create, read, update, delete and search JSON data over HTTP APIs. Ideal for small hobbies projects, MVP or just for fun, where you don't need to create your personal data storage.
## Schema
All API access is over HTTPS, and accessed from https://localhost:3000. All data is sent and received as JSON.
Blank fields are included as null instead of being omitted.
All timestamps return in ISO 8601 format:
``` ruby
YYYY-MM-DDTHH:MM:SSZ
```All responses follow the [JSON:API](https://jsonapi.org/format/) guidelines:
JSON:API is a specification for how a client should request that resources be fetched or modified, and how a server should respond to those requests.
JSON:API is designed to minimize both the number of requests and the amount of data transmitted between clients and servers. This efficiency is achieved without compromising readability, flexibility, or discoverability.
```
{
"data": {
"type": "entry",
"id": "1",
"attributes": {
// ... this entry's attributes
},
"relationships": {
// ... this entry's relationships
}
}
}
```## Pagination
Requests that return multiple items will be paginated to 20 items by default. You can specify further pages with the ```?page``` parameter. Pagination information is available inside **headers**. Example:
```
Current-Page: 1
Per-Page: 20
Link:; rel="first", ; rel="last"
Total: 464
```## Documentation
**Authentication**
API uses OAuth 2.0 token for user authorization and API authentication. Applications must be authorized and authenticated before they can fetch data.
```shcurl -X POST 'https://localhost:3000/tokens' -H 'content-type: application/json'
```
```json
{
"data": {
"id": "b14e1665-5ab3-4b71-a669-b6280d64147e",
"type": "token",
"attributes": {
"key": "uBrcpRP3QVgEJeuffuENPeSc2ObAaGoO",
"created_at": "2020-06-12T12:51:18.971Z"
}
}
}```
**Note**
You must use `Authorization: Token 80-Pk8MtTMLXT_ThBaCDuDtF1eTyVmQj` header for ALL requests.
## CRUD PACKS
**Create**
A Pack is a container of all the entries. Before you can create the entries you must create the container to get the **ID** with which you can make the calls.
```sh
curl -X POST 'https://localhost:3000/packs' -H 'content-type: application/json' -H 'Authorization: Token {KEY}'
```
### Body```json
{
"entries": [
{
"entry":
{
"name": "Davide Santangelo",
"role": "Senior Team Lead"
}
}
]
}
```### result
```json
{
"data": {
"id": "918f6a68-89f7-4f0c-aa6d-73b447d92819",
"type": "pack",
"attributes": {
"entries_count": 0,
"created_at": "2020-06-11T14:22:12.354Z",
"updated_at": "2020-06-11T14:22:12.354Z"
}
}
}```
**Read**
```sh
curl -X GET 'https://localhost:3000/packs/{PACK_ID}' -H 'content-type: application/json' -H 'Authorization: Token {KEY}'
```**Clear**
With the clear method you can clean the pack from all entries.
```sh
curl -X POST 'https://localhost:3000/packs/{PACK_ID}/clear' -H 'content-type: application/json' -H 'Authorization: Token {KEY}'
```**Delete**
With the clear method you can clean the pack from all entries.
```sh
curl -X DELETE 'https://localhost:3000/packs/{PACK_ID}' -H 'content-type: application/json' -H 'Authorization: Token {KEY}'
```## CRUD ENTRY
**Create**
```sh
curl -X POST 'https://localhost:3000/{PACK_ID}/entries' \
-H 'content-type: application/json' \
-H 'Authorization: Token {KEY}' \
-d '{ "entry": { "repo": "davidesantangelo/datoji", "private": false, "stargazers_count": 0 } }'
``````json
{
"data": {
"id": "04b7992a-40de-496b-a994-a661a9893df7",
"type": "entry",
"attributes": {
"data": {
"repo": "davidesantangelo/datoji",
"private": "false",
"stargazers_count": 0
},
"created_at": "2020-06-11T14:37:34.857Z",
"updated_at": "2020-06-11T14:37:34.857Z"
},
"relationships": {
"pack": {
"data": {
"id": "918f6a68-89f7-4f0c-aa6d-73b447d92819",
"type": "pack"
}
}
}
}
}```
You can also create multiple records at once by passing an array.
```sh
curl -X POST 'https://localhost:3000/{PACK_ID}/entries/bulk' \
-H 'content-type: application/json' \
-H 'Authorization: Token {KEY}' \
-d '{ "entries": [{ "repo": "davidesantangelo/datoji" },{ "repo": "davidesantangelo/tuns" },{ "repo": "davidesantangelo/emailhunter" }]}'
```The result in case of success is an array of IDs.
```
[
"6403b952-ce7d-4759-96d9-c8a913e166ec",
"5993d6b2-16cd-4d78-a7c8-2aba0f27af0d",
"b5861049-7c4d-485d-b795-669b9578b78d"
]
```**Read**
Use HTTP GET to read all the records or a single record.
You can also specify a param **&order=[asc/desc]** by *created_at* field. Can be one of asc or desc. Default: desc.
```sh
curl -X GET 'https://localhost:3000/packs/{PACK_ID}/entries' -H 'Authorization: Token {KEY}'
```
```json
{
"data": [
{
"id": "beb31992-0268-48b4-b5bc-b2cad0add5c7",
"type": "entry",
"attributes": {
"data": {
"repo": "davidesantangelo/datoji",
"private": "false",
"stargazers_count": 0
},
"created_at": "2020-06-11T14:59:00.581Z",
"updated_at": "2020-06-11T14:59:00.581Z"
},
"relationships": {
"pack": {
"data": {
"id": "918f6a68-89f7-4f0c-aa6d-73b447d92819",
"type": "pack"
}
}
}
},
{
"id": "b858bf82-1abf-4cb0-a9e0-2a59f1b7f30d",
"type": "entry",
"attributes": {
"data": {
"repo": "davidesantangelo/feedirss-api",
"private": "false",
"stargazers_count": 326
},
"created_at": "2020-06-11T14:37:08.293Z",
"updated_at": "2020-06-11T14:37:08.293Z"
},
"relationships": {
"pack": {
"data": {
"id": "918f6a68-89f7-4f0c-aa6d-73b447d92819",
"type": "pack"
}
}
}
}
]
}```
```sh
curl -X GET 'https://localhost:3000/packs/{PACK_ID}/entries/{ENTRY_ID}' -H 'Authorization: Token {KEY}'
```
```json
{
"data": {
"id": "04b7992a-40de-496b-a994-a661a9893df7",
"type": "entry",
"attributes": {
"data": {
"repo": "davidesantangelo/feedirss-api",
"private": "false",
"stargazers_count": 326
},
"created_at": "2020-06-11T14:37:34.857Z",
"updated_at": "2020-06-11T14:37:34.857Z"
},
"relationships": {
"pack": {
"data": {
"id": "918f6a68-89f7-4f0c-aa6d-73b447d92819",
"type": "pack"
}
}
}
}
}```
**Update**
Use HTTP PUT to update record one by one. Please note that this will not patch the record, it is full update.
``` sh
curl -X PUT 'https://localhost:3000/packs/{PACK_ID}/entries/{ENTRY_ID}' \
-H 'content-type: application/json' \
-H 'Authorization: Token {KEY}' \
-d '{ "entry": { "repo": "davidesantangelo/datoji", "private": true, "stargazers_count": 10 } }'
``````json
{
"data": {
"id": "04b7992a-40de-496b-a994-a661a9893df7",
"type": "entry",
"attributes": {
"data": {
"entry": {
"repo": "davidesantangelo/datoji",
"private": true,
"stargazers_count": 10
}
},
"created_at": "2020-06-11T14:37:34.857Z",
"updated_at": "2020-06-11T14:43:45.153Z"
},
"relationships": {
"pack": {
"data": {
"id": "918f6a68-89f7-4f0c-aa6d-73b447d92819",
"type": "pack"
}
}
}
}
}```
**Delete**
To delete a specific record use HTTP DELETE, you will receive in case of success a *204 No Content* code.
```sh
curl -X DELETE 'https://localhost:3000/packs/{PACK_ID}/entries/{ENTRY_ID}' -H 'Authorization: Token {KEY}'
```
## SearchYou can perform searches within the dataset.
Supporting:
- unquoted text: text not inside quote marks will be converted to terms separated by & operators, as if processed by plainto_tsquery.
- "quoted text": text inside quote marks will be converted to terms separated by <-> operators, as if processed by phraseto_tsquery.
- OR: logical or will be converted to the | operator.
- -: the logical not operator, converted to the the ! operator.
```sh
curl -X GET 'https://localhost:3000/packs/{PACK_ID}/search?q=datoji' -H 'Authorization: Token {KEY}'
```
```json
{
"data": [
{
"id": "b858bf82-1abf-4cb0-a9e0-2a59f1b7f30d",
"type": "entry",
"attributes": {
"data": {
"repo": "davidesantangelo/datoji",
"private": true,
"stargazers_count": 10
}
"created_at": "2020-06-11T14:37:08.293Z",
"updated_at": "2020-06-11T14:37:08.293Z"
},
"relationships": {
"pack": {
"data": {
"id": "918f6a68-89f7-4f0c-aa6d-73b447d92819",
"type": "pack"
}
}
}
}
]
}```
## Limitations
* Requests are rate-limited to **400** per 5 minutes per IP address.
* There is no limit imposed on the number of entries or packs records, but please **don't abuse** it since it's a service i offer free of charge.## Built With
- [Ruby on Rails](https://github.com/rails/rails) — Our back end API is a Rails app. It responds to requests RESTfully in JSON.
- [PostgreSQL](https://www.postgresql.org/) — Our main data store is in Postgres.
- [Redis](https://redis.io/) — We use Redis as a cache and for transient data.
- [FastJSONAPI](https://github.com/Netflix/fast_jsonapi) — A lightning fast JSON:API serializer for Ruby Objects.
- [Textacular](https://github.com/textacular/textacular) — Textacular exposes full text search capabilities from PostgreSQL.
- [Rack::Attack](https://github.com/kickstarter/rack-attack) — Rack middleware for blocking & throttling abusive requests.
- [Pagy](https://github.com/ddnexus/pagy) — The ultimate pagination ruby gem.## To Do
- [x] Bulk Insert
- [ ] GraphQL
- [ ] Webhook## Buy me a coffee
If you want to support me in server costs, consider [buying me a coffee](https://www.buymeacoffee.com/582rhJH)! Thanks!
## Spread The Voice
[![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=A%20tiny%20JSON%20storage%20service.%20Create,%20Read,%20Update,%20Delete%20and%20Search%20JSON%20data&url=https://github.com/davidesantangelo/datoji&hashtags=json,rest,rails,developers)
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/davidesantangelo/datoji. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).