![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Automatic generated APIs are great. I am a big fan of projects like JSON-server and sails.js. The intend for this project is to set the koa development first. People learn how to use Koa, structure there app using koa-mount and koa-route.
On the other hand I strongly believe in dao modules. Modules that access each a single collection on a database and provides standard methods to retrieve data from a resource.
In first place this project is designed to use daos prepared by tmysqlpromisedao. A librarie to provide dao-modules to access the mysqldatabase.
Utilising these conventions dao2koa can provide a RESTful API not just for mysql but also for any other data resource that can be accessed through a dao.
var app = new Koa();
var apiRouter = dao2koa.daoToRestRouter(dao,{/*options*/});
app.use(mount('/endpoint/',apiRouter));
The generated API provides the following endpoints
GET / - list all using the dao's getAll methods
the value need to be higher (alphabetic, numbers, dates)
GET /:id - retrieve a single item by Id using the daos getById method.
POST / or GET /create to create a new entry in the collection.
uses the daos insert method to add a new item to the table.
the items properties can be send using post or the URLs querystring
PUT /:id/ or GET /update/:id - to update an item
uses the daos save method to update an entry of the table.
the properties can be send using post or querystring
DELETE /:id or GET /delete/:id to remove an item from the collection.
provinging an API which is that powerfull is very risky, but this API generator is meaned to be used in production. So there are serveral ways to implement authentication validation and trigger further methods like logging clearing related data, adding statistics and/or handle denormalization.
Using dao2koa, you have two ways to change the generated API. One way is the direct way, as you would do it with any koa middleware. Handle the route before the API is utilized. Add logging and general authentication, if fact anything you could imagine. Or implement yourself.
The second is for convinienve. By passing an options object as second parameter to the daoToRestRouter - method. The options are:
To have be most clear in your code and avoid looking to much for documentation copy the following object as options to daoToRestRouter.
{
inputFilter: async function(ctx,newObject, oldObject){return newObject;},
outputFilter: async function(ctx, object){return object;},
defaultOrder: undefined,// let database decide.
fetchableFields: [],
fulltextFields: [],
searchableFields: [],
defaultPageSize: 10,
maxPageSize: 100,
allowChangesOnGet: true
}
As you see the intputFilter and outputFilter are async functions. Means you can read permissions, read other tables to validate the changes to make. You might want to use transactions.
Use the second method provided by this module: transactionMiddleware - takes the db from tmysqlpromisedao. add a transaction connection to ctx.connection.
Any transaction connection added to ctx.connection is used by the generated API. Such a middleware is a good way to implement a standard way of initializing a transaction in your entire project.
Now it is time to implement some cool application using - Koa2 to use modern Javascript with async await. - tmysqlpromisedao to implement a standard way for data access in your application. - and now dao2koa to get your API up and running as fast as you can and focus.
Tobias Nickel german software engineer located in Shanghai.
FAQs
provide RESTful API for Mysql using tmysqlpromisedao + koa2
We found that dao2koa demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.