All Projects β†’ galvez β†’ yamlful

galvez / yamlful

Licence: other
YAML-based HTTP client code generation

Programming Languages

javascript
184084 projects - #8 most used programming language
Vue
7211 projects

Projects that are alternatives of or similar to yamlful

nuxt-stripejs
πŸ’³ NuxtJS module for Stripe.js which loads only when required and w/ retry mechanism
Stars: ✭ 17 (-77.92%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-jsonld
A Nuxt.js module to manage JSON-LD in Vue component.
Stars: ✭ 198 (+157.14%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
lumen-cms
GraphQL API-First CMS based on NodeJS and Vue 2, Nuxt and Vuetify
Stars: ✭ 77 (+0%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-ts-module
A tiny module to use Typescript within Nuxt.js application.
Stars: ✭ 21 (-72.73%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-modules
AX2's Nuxt modules
Stars: ✭ 30 (-61.04%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-humans-txt
πŸ§‘πŸ»πŸ‘©πŸ» "We are people, not machines" - An initiative to know the creators of a website. Contains the information about humans to the web building - A Nuxt Module to statically integrate and generate a humans.txt author file - Based on the HumansTxt Project.
Stars: ✭ 27 (-64.94%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
applicationinsights-module
Application Insights module for NuxtJS
Stars: ✭ 14 (-81.82%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
Surmon.me
πŸ†’ My personal website and blog, powered by @vuejs (3)
Stars: ✭ 1,767 (+2194.81%)
Mutual labels:  restful, nuxt, nuxtjs
nuxt-prune-html
πŸ”Œβš‘ Nuxt module to prune html before sending it to the browser (it removes elements matching CSS selector(s)), useful for boosting performance showing a different HTML for bots/audits by removing all the scripts with dynamic rendering
Stars: ✭ 69 (-10.39%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-ghost
Easy Ghost content API integration with Nuxt.js.
Stars: ✭ 27 (-64.94%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
vue-plausible
Plausible Analytics Vue.js Plugin and NuxtJS Module
Stars: ✭ 107 (+38.96%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-winston-log
Nuxt module for logging SSR errors using winston
Stars: ✭ 41 (-46.75%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-typo3
TYPO3 Frontend rendered in Vue.js and Nuxt (frontend for EXT:headless)
Stars: ✭ 66 (-14.29%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
supabase
An easy way to integrate Supabase with NuxtJS
Stars: ✭ 39 (-49.35%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-gsap-module
GSAP module for Nuxt.js
Stars: ✭ 183 (+137.66%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-quasar
Nuxt module for the Quasar Framework
Stars: ✭ 36 (-53.25%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
k-domains
A simple module to manage multiple subdomains with just one project
Stars: ✭ 41 (-46.75%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
jooger.me
πŸ‘ My personal website,powered by @nuxt
Stars: ✭ 39 (-49.35%)
Mutual labels:  restful, nuxt, nuxtjs
nuxt-speedkit
nuxt-speedkit will help you to improve the lighthouse performance score (100/100) of your website.
Stars: ✭ 401 (+420.78%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-stencil
Easy Stencil.js component library integration with Nuxt.js.
Stars: ✭ 16 (-79.22%)
Mutual labels:  nuxt, nuxtjs, nuxt-module

This project is no longer maintained.

Using YAML to define code snippets is a terrible idea. I don't know what I was thinking.

Check out fastify-vite and fastify-api for a better path forward.

API clients should be autogenerated from the server code that implements them.


yamlful is a utility for HTTP client code generation from YAML:

sample:
  - method: get
    get: /resource/:id/subresource/:subId
  - method: create
    post: /resource/:id/subresource
  - method: update
    put: /resource/:id/subresource/:subId
  - method: remove
    delete: myresource/

It uses a simple pattern to determine function arguments and HTTP parameters, so that methods that use PUT or POST get a payload and others don't, while preserving the URL parameters in each YAML-defined endpoint.

The above YAML file can be used to generate a snippet like this:

const sample = {
  get: (id, subId, params = {}) => {
    return client.get(`/resource/${id}/subresource/${subId}`, { params })
  },
  create: (id, payload, params = {}) {
    return client.post(`/resource/${id}/subresource`, payload, { params })
  },
  update: (id, subId, payload, params = {}) {
    return client.put(`/resource/${id}/subresource/${subId}`, payload, { params })
  },
  remove: (id, params = {}) => {
    return client.delete(`myresource/${id}`, { params })
  }
}

Motivation

Boilerplate JavaScript for exposing HTTP API client methods is pretty simple most of the time.

However, when you have a huge API with dozens of different resources, more streamlined YAML configuration makes it easier to maintain it while dealing with constant change. yamlful was born by identifying these key simple patterns when connecting JavaScrit methods to JSON HTTP APIs.

Nuxt.js module

Bundled in this repository is a Nuxt.js module (yamlful-nuxt) that uses yamlful to generate similar code, integrating itself to @nuxtjs/axios and exposing API methods to Vue pages.

npm install yamlful-nuxt --save

In nuxt.config.js:

export default {
  // Thanks to Pooya Parsa for the awesome Nuxt Axios module
  // Note that @nuxtjs/axios is automatically required by yamlin
  axios: {
    // Thanks to Ben Howdle for the amazing API testing service
    baseURL: 'https://reqres.in/'
  },
  // By default, yamlful will look for .yml files in Nuxt's srcDir
  modules: ['yamlful-nuxt']
}

In pages/index.vue:

export default {
  async asyncData ({ $api }) {
    // $api available in SSR context
    const response = await $api.users.get(1)
    return {
      user: response.data
    }
  },
  data: () => ({
    user: {}
  }),
  methods: {
    async loadTwo() {
      // this.$api available in the client context
      const response = await this.$api.users.get(2)
      this.user = response.data
    }
  }
}

Raw methods

The Nuxt.js module also allows you to inline JavaScript in YAML for defining raw methods:

Input:

  - method: custom
    raw: |
      (customParam) => {
      	client.get(`/customresource/${customParam}`)
      }

Output:

  custom: (customParam) => {
    client.get(`/customresource/${customParam}`)
  }

Note that client is used to inject Nuxt's axios instance.

See the API template used for the Nuxt module.

Other frameworks

Modules and extensions for other frameworks can be implemented using the main exported function in the yamlful package. PRs are very much welcome.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].