Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Javascript network client library for Akita protocol.
Akita protocol is based on HTTP, which is a superset of RESTful.
Compared to the basic RESTful, Akita support list paging, limit, filters, update/remove multi record.
If server has an error, the response body should contain error message and error code optionally.
{
"error": "Can not connect to database",
"code": 1233 // optional
}
GET /path/to/res
Query params:
param | type | default |
---|---|---|
_limit | number | |
_sort | string | |
_search | string | |
...filters | string/Object |
Result:
[ /* Records list */
{ id: 1 /* Record 1 */ },
{ id: 2 /* Record 2 */ }
]
Example:
Find all records sort by createdAt
DESC
GET /res?_sort=-createdAt
await akita('res').find().sort('-createdAt')
Find 100 records where user
is 12
GET /res?user=12&_limit=100
await akita('res').find({ user: 12 }).limit(100)
GET /path/to/res/paginate
Query params:
param | type | default |
---|---|---|
_page | number | 1 |
_limit | number | |
_sort | string | |
_search | string | |
...filters | string/Object |
Result:
{
"total": 121, // total record
"page": 1, // current page, default 1
"limit": 10, // page limit
"totalPage": 13,
"previous": 0, // previous page index, zore for none
"next": 2, // next page index, zore for none
"search": "",
"results":[ /* Records list */
{ id: 1 /* Record 1 */ },
{ id: 2 /* Record 2 */ }
]
}
Example:
Find records sort by createdAt
DESC
GET /res/paginate?_sort=-createdAt
await akita('res').paginate().sort('-createdAt')
Find records where user
is 12
GET /res/paginate?user=12&_page=2
await akita('res').paginate().where('user',12).page(2)
Find records where views
great than 100
GET /res/paginate?views[$gt]=100
await akita('res').paginate().where('views').gt(100)
GET /path/to/res/{ID}
Query params:
param | type | default |
---|---|---|
...filters | string/Object |
Result:
{
"id": 123,
// ... others
}
Example:
find record 123 and ensure user
is 12
GET /res/123?user=12
await akita('res').findById(123).where({ user: 12})
GET /path/to/res/count
Query params:
param | type | default |
---|---|---|
_search | string | |
...filters | string/Object |
Result:
{
"count": 123
}
POST /path/to/res
Post body:
{
"title": "my book",
// ... others data for creation
}
Result:
{
"id": 123,
"title": "my book",
// ... others data for creation
}
DELETE /path/to/res/{ID}
Query params:
param | type | default |
---|---|---|
...filters | string/Object |
DELETE /path/to/res
Query params:
param | type | default |
---|---|---|
_limit | number | |
_sort | string | |
_search | string | |
...filters | string/Object |
PATCH /path/to/res/{ID}
Query params:
param | type | default |
---|---|---|
...filters | string/Object |
Post body:
{
"title": "my book",
// ... others data for update
}
Result:
{
"id": 123,
"title": "my book",
// ... others data for creation
}
PATCH /path/to/res
Query params:
param | type | default |
---|---|---|
_limit | number | |
_sort | string | |
_search | string | |
...filters | string/Object |
Post body:
{
"title": "my book",
// ... others data for update
}
Result:
{
"count": 2, // updated records count
"ids": [127, 342] // updated records id
}
option | type | defualt | description |
---|---|---|---|
debug | boolean | false | enable debug mode |
apiRoot | string | '' | API root path |
fetch | Function | window.fetch | custom fetch function |
FormData | Function | window.FormData | custom FormData class |
init | Object | fetch(url,init) init options https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters |
create a query object
create a new client instance
resolve a client instance by
key
, create a new instance if not found
update client instance options
send a http request
send a http request with GET method
send a http request with POST method
send a http request with PUT method
send a http request with PATCH method
send a http request with DELETE method
send a http request with HEAD method
send a http request with OPTIONS method
send a http request with TRACE method
send a http request with CONNECT method
Create new record
Specifies custom param.
Find multi records without paging.
Find records with paging.
Find one record by filters.
Find one record by id.
Update multi records or one record by id.
Remove multi records or one record by id.
Specifies a search param
Specifies query filter conditions
Specifies a filter condition
Specifies a $lt filter condition
Specifies a $lte filter condition
Specifies a $gt filter condition
Specifies a $gte filter condition
Specifies query sort
Specifies query page
Specifies query page limit or update/remove limit.
Execute the query.
import akita from 'akita';
const client = akita.create({ /* options */});
// import default client instance
import akita from 'akita';
// set options for defualt instance
akita.setOptions({ /* options */});
// create new instance
const client = akita.create({ /* options */});
// set options for new client
client.setOptions({ apiRoot: 'http://your.domain/' /* other options */});
// send a POST request
await client.post('blog',{ body:{ title: 'my book' } });
// create record by akita query
await client('blog').create({ title: 'my book' });
// find records with paging
await client('blog').paginate();
// find one record by id
await client('blog').findById(12);
// find one record by filters
await client('blog').findOne({ category: 'js' }).sort('-createdAt');
// update multi records
await client('blog').update({ hot: true }).sort('-views').limit(10);
// update one record by id
await client('blog').update(12, { hot: true });
// update one record by filters & limit
await client('blog').update({ hot: true }).sort('-views').limit(1);
// remove on record by id
await client('blog').remove(12);
// remove multi records by filters
await client('blog').remove({ state: 1 });
// or
await client('blog').where('views').lt(100).remove();
This project is licensed under the terms of the MIT license
FAQs
Http client for NodeJs / browser and WeChat, based on fetch()
We found that akita demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.