fully-api

3.2.1 • Public • Published

fully-api

api framework for fully stacked LLC

Quickstart

You must create the database you wish to use with your fullyAPI project and set up the information for your default user in your settings file. Once you configure the appropriate base environment variables, you can boot the system and it will generate the default user and assocaited base api tables and records (users, session, user sessions, user auth). Sensitivie and auth related user data is stored in the table fsapi_user_auth to protect against sensitive user data getting out publically from the system in the event developers SELECT * from fsapi_user table.

Initializing server

Configure your server options
Server options can be configured in the config.NODE_ENV.ts/config.NODE_ENV.js files.

Import & Start Server

In your main file (index.js/server.js) call the following to set up and run a new instance of fully-api

After you call initialize(), you can configure custom routes. Especially if you need a custom middleware for a specific route such as multer for file upload via multipart/form-data (sudocode in example below).

requestPipeline takes an optional callback function and has the following parameters:

  • pipeline_result
  • req
  • res


pipeline_results is the resolved response from your endpoint's deferred.resolve() from your endpoint called in the controller file. by using this callback you are then responsible for telling the server to respond to the client res.status(200).send(pipline_results). This optional callback is useful if you want to customize the server response to be different than the default (res.status(200).send(pipline_results);). Cases where you may wish to do this would be responding with res.download or another such express response options instead of the fully-api default option.

Default routes already exist for each verb and have the following structure. Differentiate your route paths from this format by either appending or prepending. Existing/default routes: /:area/:controller/:serviceCall/:version?

var fullyAPI = require('fully-api').FullyAPI;
var multer = require('multer');
var multerS3 = require('multer-s3');
var AWS = require('aws-sdk');


var api = new fullyAPI()

api.initialize()
.then(function(){
    //This is where you can configure custom routes. 
    var multer_upload = multer();
    //this is a custom route handler that uses the fully-api routing but specifies that multer should be used as the middleware since multipart/form-data will be expected by this endpoint.
    api.app.post('upload/:area/:controller/:serviceCall/:version?', multer_upload.array('photo',1), function (req:any, res:any, err:any) {
        console.log(req.body)
        fullyAPI.requestPipeline(req, res, 'POST');
    });

    //this configures the default system routing. It should be called after specifying any custom routes because it also specifies the 404 not found catch-all route. 
    api.configureRoutes();
    api.startServer()
})



Endpoints_ext Locations The file locations object in the configuration file specifies where the server should look to load all static files. The only one you should change is endpoints_ext. Changing math to any non-extension files should only be done with care, if you are intending to overright the core system static files.


Utilities, DataAccess, AccessControl Extensions Each core service has an extension file that will be loaded and availible via Service.extensions.MethodName(). Do not mofidy core service files, as any changes will get overwritten by update releases. The server expects to load extension files from the same directory as your primary script. (Whereever the file you launch your pain process is located. hint: see package.json, "main" attribute.)

DB Namespace:

all system generated tables are namespaced with the prefix fsapi_{{table_name}}. Removing any existing columns from system generated tables may break internal functions. Adding new columns by different/new names to these tables is fine.

DB Conventions:

We recommend db migrate to manage all of your custom database table creation and mofifications. We recommend using the pre-installed extension for generating your primary keys to remain consistant with the system tables: id VARCHAR(36) NOT NULL DEFAULT uuid_generate_v1() primary key
Example of a create table with foreign key references:

CREATE TABLE fsapi_user_session ( 
id VARCHAR(36) NOT NULL DEFAULT uuid_generate_v1() primary key, 
user_id VARCHAR(36) NOT NULL references fsapi_user(id), 
session_id VARCHAR(36) NOT NULL references fsapi_session(id), 
rel_type VARCHAR(50) NOT NULL DEFAULT 'default', 
created_at timestamp not null default current_timestamp, 
data jsonb);



MetaData column

All system generated tables have a jsonb metadata column called data, should you need to store anything on the fly, that you do not with to make part of your relational table. We do not recommend storing any information you will query on or filter on frequently in this manner.



Environment Variables


basic environment variables

All environment variables needed for system boot are located in the config.NODE_ENV.js/config.NODE_ENV.ts file.


Twillio SMS OTP environment variables

There are two endpoints related to account creation and authentication using SMS OTPs via twillio. These are POST sms_otp to send the one time passcode to the phone number provided. The other is POST otp_signIn to authenticate using the OTP. If no account is found, an account will be created with that phone number and authenticated using the phone number. The following enviornment variables must be configured for this process with TWILIO to work.

  • TWILIO_ACCOUNT_SID
  • TWILIO_AUTH_TOKEN
  • TWILIO_SERVICE_ID
  • TWILIO_ACTIVE = 'true'
    • If you attempt to initialize twilio without setting the SID, TOKEN, and ID before setting TWILIO_ACTIVE to true, your api will error on boot

Package Sidebar

Install

npm i fully-api

Weekly Downloads

55

Version

3.2.1

License

MIT

Unpacked Size

1.91 MB

Total Files

67

Last publish

Collaborators

  • fullystacked