Git Product home page Git Product logo

kontenbase-php's Introduction

Kontenbase

This is the Official PHP client for Kontenbase API.

Kontenbase is a no-code backend API platform or Backend as a Service (BaaS) that allows you to create a backend API as fast as possible. We make it easy for developers to build backend API without having to touch backend code at all.

Visit Kontenbase for more information and see our documentation for more technical details.

API Documentation

For API documentation, visit Kontenbase API Reference.

Installation

To install the SDK you can use Composer or directly download the source and extract to your directory. If you’re using Composer, run this following command:

composer require kontenbase/sdk

Usage

Before you begin, you need to sign up on Kontenbase Dashboard to retrieve an API key of your project.

Create a client

<?php

use Kontenbase\KontenbaseClient;

$kontenbase = new KontenbaseClient([
	'apiKey': 'YOUR_API_KEY' // Your API Key from app.kontenbase.com
]);

Authentication

Register

$res = $kontenbase->auth->register([
	'firstName' => 'Ega',
	'lastName' => 'Radiegtya',
	'email' => '[email protected]',
	'password' => 'password'
]);

echo $res['user']; // The data of registered user
echo $res['token']; // The token of registered user

Login

$res = $kontenbase->auth->login([
	'email' => '[email protected]',
	'password' => 'password'
]);

echo $res['user']; // The data of logged-in user
echo $res['token']; // The token of logged-in user

Get user info

$res = $kontenbase->auth->user();

echo $res['user'];

Update user info

$res = $kontenbase->auth->update([
	'firstName' => 'Ega'
]);

echo $res['user'];

Logout

$res = $kontenbase->auth->logout();

Database

Create a new record

$res = $kontenbase->service('posts')->create([
	'name' => 'Post 1',
	'notes' => 'Hello Kontenbase'
]);

echo $res['data'] // The data of the new record

Get a record by ID

$res = $kontenbase->service('posts')->getById('605a251d7b8678bf6811k3b1');

echo $res['data'] // The data of the record

Find records

Get all records

$res = $kontenbase->service('posts')->find();

echo $res['data'] // The data of all records

Find records and modify the result

// limit
$res = $kontenbase->service('posts')->find([
	'limit' => 10
]);
// sort
// ascending: 1
// descending: -1
$res = $kontenbase->service('posts')->find([
	'sort' => ['name' => 1]
]);
// skip
$res = $kontenbase->service('posts')->find([
	'skip' => 10
]);
// select
$res = $kontenbase->service('posts')->find([
	'select' => ['name', 'notes']
]);
// lookup all fields
$res = $kontenbase->service('posts')->find([
	'lookup' => '*'
]);

// lookup spesific fields
$res = $kontenbase->service('posts')->find([
	'lookup' => ['categories']
]);

// lookup but only show ids
$res = $kontenbase->service('posts')->find([
	'lookup' => ['_id' => '*']
]);

Find records with criteria

// equals
$res = $kontenbase->service('posts')->find([
	'where' => [
		'name' => 'Ega'
	]
]);
// does not equal
$res = $kontenbase->service('posts')->find([
	'where' => [
		'name' => ['$ne' => 'Ega']
	]
]);
// contains
$res = $kontenbase->service('posts')->find([
	'where' => [
		'notes' => ['$contains' => 'hello']
	]
]);
// does not contain
$res = $kontenbase->service('posts')->find([
	'where' => [
		'notes' => ['$notContains' => 'hello']
	]
]);
// matches any of
$res = $kontenbase->service('posts')->find([
	'where' => [
		'name' => ['$in' => ['Ega', 'Radiegtya']]
	]
]);
// does not match any of
$res = $kontenbase->service('posts')->find([
	'where' => [
		'name' => ['$nin' => ['Ega', 'Radiegtya']]
	]
]);
// less than
$res = $kontenbase->service('posts')->find([
	'where' => [
		'total' => ['$lt' => 10]
	]
]);
// less than or equals
$res = $kontenbase->service('posts')->find([
	'where' => [
		'total' => ['$lte' => 10]
	]
]);
// more than
$res = $kontenbase->service('posts')->find([
	'where' => [
		'total' => ['$gt' => 10]
	]
]);
// more than or equals
$res = $kontenbase->service('posts')->find([
	'where' => [
		'total' => ['$gte' => 10]
	]
]);

Update record

$res = $kontenbase->service('posts')->updateById('605a251d7b8678bf6811k3b1', [
	'notes' => 'Hello world'
]);

Delete record

$res = $kontenbase->service('posts')->deleteById('605a251d7b8678bf6811k3b1');

Link a record to create relation

$res = $kontenbase->service('posts')->link('605a251d7b8678bf6811k3b1', [
	'categories' => '61d26e8e2adb12b85c33029c'
]);

Unlink a record from its relation

$res = $kontenbase->service('posts')->unlink('605a251d7b8678bf6811k3b1', [
	'categories' => '61d26e8e2adb12b85c33029c'
]);

Count total records

Count all records

$res = $kontenbase->service('posts')->count();

Count records that match given criteria

$res = $kontenbase->service('posts')->find([
	'where' => [
		'name' => 'Ega'
	]
]);

Storage

Upload a file

$file = fopen('/path/to/file', 'r');
$res = $kontenbase->storage->upload($file);

echo $res['data'] // The data of the uploaded file

Feedback

Please use our GitHub Issues for high-level feedback. Also you can join our Discord server.

kontenbase-php's People

Contributors

nuraskiah avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.