-
Notifications
You must be signed in to change notification settings - Fork 1
node http api
-
Determine a path prefix for the object model (ex. /object/)
-
Go to your node webserver and make sure you have the connect line (from the node instructions) outside your http handlers
-
Next add the following to the top of your http handler file
import {HTTP as ormHTTP} from 'tanjentjs-ts-orm/node';
-
Then add this to your request handler
if (requestData.url.startsWith('/object')) { ormHTTP.handle(requestData, responseData).then( (response: string) => responseData.end(response), (err: string) => { console.error('ORM Error', err); responseData.statusCode = 500; responseData.end(''); } ); } else { // The rest of your handler }
Note: If your prefix has more than one slash in it please add a third argument which is the number of slashes + 1 (2 by default). This is needed to properly find path components
Hint: This system does not handle any authentication or authorization for you, you will need to manage that on your own and potentially add it above/below the handle method call
-
Finally make sure your objects get loaded and ran, this is needed to prime the system by running the decorators
-
You may then use the following api
- /object/{registerParam}.{className}
- POST - This runs a search. The body payload should be a subset of the fields in the object to search for.
- PUT - This creates an object. The body payload should be the fields you want set in the database. Returns the resulting object.
- /object/{registerParam}.{className}/{id}
- GET - This fetches an object from the system by id (a property which is automatically added to all (objects).
- PUT - This updates an object. The body payload should be the fields to update. Returns the resulting object.
- DELETE - This deletes an object.
- /object/{registerParam}.{className}
You can supply a second parameter to both register and field which specifies if the object or fields should be hidden from the api. In both cases the default is to show all objects and fields in the api