Skip to content

Instantly share code, notes, and snippets.

@Kelin2025
Created March 17, 2018 19:29
Show Gist options
  • Save Kelin2025/75dd9c7d6471451becfc8e95b270dbdd to your computer and use it in GitHub Desktop.
Save Kelin2025/75dd9c7d6471451becfc8e95b270dbdd to your computer and use it in GitHub Desktop.
Services tree
import fetch from '@apicase/adapter-fetch'
import { ApiTree } from '@apicase/services'
import { ApiService } from '@apicase/core'
const Root = new ApiService(fetch, { url: '/api' })
const api = new ApiTree(Root, [
{ url: 'posts', children: [
{ name: 'postsGetAll', url: '', method: 'GET' },
{ name: 'postsCreate', url: '', method: 'POST' },
{ name: 'postsGetOne', url: ':id', method: 'GET' },
{ name: 'postsUpdOne', url: ':id', method: 'PUT' },
{ name: 'postsRmvOne', url: ':id', method: 'DELETE' }
] },
{ url: 'profile', children: [/*...*/] }
])
api('postsGetAll').doRequest()
api('postsCreate').doRequest()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment