Skip to content

Instantly share code, notes, and snippets.

View Kelin2025's full-sized avatar
๐Ÿ‘‹
Let him cook

Anton Kosykh Kelin2025

๐Ÿ‘‹
Let him cook
View GitHub Profile
@Kelin2025
Kelin2025 / apicase-hooks.js
Created August 22, 2017 15:57
Apicase hooks
import { Container, ApiAbort } from 'apicase'
// For example, we have user info and validation schema for data
import user from './user'
import schema from './schema'
// For example we have route that create a new product
// And we have to sent title of product
const services = {
@Kelin2025
Kelin2025 / apicase-watchers.js
Last active May 8, 2022 04:11
Apicase watchers example
import { Container } from 'apicase'
export default new Container({
services: {
hello: {
url: '/hello',
watchers: [
(ctx, key, value) => {
switch (key) {
case 'calls':
@Kelin2025
Kelin2025 / apicase-call.js
Last active August 22, 2017 17:26
Apicase call example
import apis from './container.js'
// Note that it always resolves
let res = await apis.go(serviceName, queryData, params)
// You can handle result as before
// But you often do not have to do it
// because of next features I'll talk about
if (res.ok) {
console.log('Success')
@Kelin2025
Kelin2025 / apicase-mixins.js
Created August 22, 2017 16:20
Apicase mixins example
import { Container } from 'apicase'
export default new Container({
services: {
posts: {
url: '/posts',
// You can use it for shortcuts
// or more interesting computed properties
mixins: {
success () {
@Kelin2025
Kelin2025 / 1.container-level.js
Created August 22, 2017 18:18
3 levels of apicse
import { Container, ApiAbort } from 'apicase'
// I separated it for better understanding
import services from './services'
// Pass authorization token to every service
const headers = () => ({
token: localStorage.getItem('token')
})
@Kelin2025
Kelin2025 / PolyFills.js
Created September 22, 2017 15:00
Chto eto?
/**
* Array.find
*/
if (!Array.prototype.find) {
Array.prototype.find = function(predicate) {
'use strict';
if (this === null) {
throw new TypeError('Array.prototype.find called on null or undefined');
}
if (typeof predicate !== 'function') {
@Kelin2025
Kelin2025 / 1_within.js
Created September 24, 2017 00:03
For apicase website
import Apicase from 'apicase'
const headers = { 'Content-Type': 'multipart/form-data' }
const catalog = {
url: 'catalog',
services: [
{ name: 'category', url: 'categories', method: 'get' },
{ name: 'platform', url: 'platforms', method: 'get' },
{ name: 'apps', url: 'apps', method: 'get' },
const asyncPipe = (...fns) => arg => {
const res = fns[0](arg)
const slice = fns.slice(1)
const next = slice.length ? asyncPipe(...slice) : identity
const isPromise = typeof res === 'object' && 'then' in res
return isPromise ? res.then(next) : next(res)
}
const add = a => b => a + b
@Kelin2025
Kelin2025 / init.js
Last active March 17, 2018 18:41
Apicase init
import { apicase } from '@apicase/core'
import fetch from '@apicase/adapter-fetch'
const doRequest = apicase(fetch)
@Kelin2025
Kelin2025 / request.js
Created March 17, 2018 18:42
Apicase request
doRequest({ url: '/api/posts' })
.on('done', res => console.log(res))
.on('fail', res => console.warn(res))