Skip to content
/ floxum Public

Floxum adds realtime support to Strapi applications

Notifications You must be signed in to change notification settings

mxvsh/floxum

Repository files navigation

Floxum (WIP)

Floxum is a Socket IO connector for Strapi

Artboard

Example

floxum.services('todo', 'find', { _limit: 1 }).then((data) => {
   console.log(data)
})
floxum.services('todo', 'delete', { id: 1 }).then((data) => {
   console.log("Successfully deleted todo")
})

Installation

The installation will also work for existing Strapi project.

Step 1

Install the following module inside your React project:

yarn add @floxum/react

Step 2

Install the following module inside your Strapi application:

yarn add @floxum/core

Step 3

Create a new file inside your React application to setup Floxum at src/providers (or anywhere you'd want) named floxum.js, and paste the following code.

import Floxum from '@floxum/react'

const floxum = Floxum('http://localhost:1337')

export default floxum

Change the host string to your Strapi host.

Step 4

Inside your Strapi applicaiton, go to config/functions/bootstrap.js, and import Floxum then call it inside the export module with strapi parameters:

"use strict";
const folxum = require("@floxum/core");

module.exports = async () => {
  folxum(strapi);
};

You're now good to go!

Step 5

Inside your Rect project (in any component) import Floxum and and test it by calling ping function, like this:

useEffect(() => {
  floxum.ping().then(() => {
    console.log('working')
  })
}, []);

Functions

Here are the functions available in Floxum API

ping

This will test the connection with the Strapi server. Returns a Promise.

register

This function is used to register a user. Example:

floxum.register({ username: 'xxxxx', email: 'xxxxx', password: '****'})
	.then(data => {
		// data: jwt and others values
	})
	.catch(err => {
		// err: Strapi error
	})

login

This function is used to login a user. Example:

floxum.login({ identifier: 'xxxxx', password: '****'})
	.then(data => {
		// data: jwt and others values
	})
	.catch(err => {
		// err: Strapi error
	})

authenticate

This function can be used to get the currently logged in user's data, using token from localStorage Example:

floxum.authenticate()
	.then(data => {
		// data: user data and others values
	})
	.catch(err => {
		// err: Strapi error
	})

services

This function can be used to execute services for any API registered on Strapi. The following example will create a new entry in "todo" collection. You can also execute, find, update or delete services. Example:

floxum.services('todo', 'create', { todo: 'Grab coffee' })
	.then(data => {
		// data: response from the Strapi
	})
	.catch(err => {
		// err: Strapi error
	})