Floxum is a Socket IO connector for Strapi
floxum.services('todo', 'find', { _limit: 1 }).then((data) => {
console.log(data)
})
floxum.services('todo', 'delete', { id: 1 }).then((data) => {
console.log("Successfully deleted todo")
})
The installation will also work for existing Strapi project.
Install the following module inside your React project:
yarn add @floxum/react
Install the following module inside your Strapi application:
yarn add @floxum/core
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.
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!
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')
})
}, []);
Here are the functions available in Floxum API
This will test the connection with the Strapi server. Returns a Promise.
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
})
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
})
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
})
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
})