|
| 1 | +<template lang="pug"> |
| 2 | +div |
| 3 | + div(class="w-full max-w-6xl mx-auto mt-24 p-4") |
| 4 | + h1(class="text-center mb-8 text-5xl font-bold") Json Api Response Converter |
| 5 | + |
| 6 | + p(class="text-center mb-4") Normalize your JSON:API response. |
| 7 | + |
| 8 | + p(class="text-center badges") |
| 9 | + a(href="https://www.paypal.me/guillaumebriday") |
| 10 | + img(src="https://img.shields.io/badge/Donate-PayPal-green.svg") |
| 11 | + |
| 12 | + a(href="https://www.npmjs.com/package/json-api-response-converter") |
| 13 | + img(src="https://img.shields.io/npm/dt/json-api-response-converter.svg") |
| 14 | + |
| 15 | + a(href="https://www.npmjs.com/package/json-api-response-converter") |
| 16 | + img(src="https://img.shields.io/npm/v/json-api-response-converter.svg") |
| 17 | + |
| 18 | + a(href="https://github.com/guillaumebriday/json-api-response-converter") |
| 19 | + img(src="https://github.com/guillaumebriday/json-api-response-converter/workflows/Lint/badge.svg") |
| 20 | + |
| 21 | + a(href="https://github.com/guillaumebriday/json-api-response-converter") |
| 22 | + img(src="https://github.com/guillaumebriday/json-api-response-converter/workflows/Test/badge.svg") |
| 23 | + |
| 24 | + a(href="https://github.com/guillaumebriday/json-api-response-converter") |
| 25 | + img(src="https://img.shields.io/github/license/guillaumebriday/json-api-response-converter.svg") |
| 26 | + |
| 27 | + a(href="https://json-api-response-converter.netlify.com/") |
| 28 | + img(src="https://api.netlify.com/api/v1/badges/f48191db-a459-4ab4-849f-10ea970915af/deploy-status") |
| 29 | + |
| 30 | + h2(class="text-center text-2xl font-bold my-4") Essential links |
| 31 | + |
| 32 | + ul(class="text-center") |
| 33 | + li |
| 34 | + a(href="https://github.com/guillaumebriday/json-api-response-converter" target="_blank" rel="noopener") Github |
| 35 | + |
| 36 | + li |
| 37 | + a(href="https://www.npmjs.com/package/json-api-response-converter" target="_blank" rel="noopener") Npm |
| 38 | + |
| 39 | + h2(class="text-center text-2xl font-bold my-4") Live demo |
| 40 | + |
| 41 | + p Past your API response here |
| 42 | + |
| 43 | + div(class="flex border-t") |
| 44 | + div(class="item") |
| 45 | + codemirror(v-model="response" :options="options") |
| 46 | + |
| 47 | + pre(class="item pre") {{ formattedResponse }} |
| 48 | +</template> |
| 49 | + |
| 50 | +<script> |
| 51 | +import { codemirror } from 'vue-codemirror' |
| 52 | +import JsonApiResponseConverter from '../../src/main.js' |
| 53 | +
|
| 54 | +import 'codemirror/lib/codemirror.css' |
| 55 | +import 'codemirror/theme/material.css' |
| 56 | +
|
| 57 | +export default { |
| 58 | + components: { |
| 59 | + codemirror |
| 60 | + }, |
| 61 | +
|
| 62 | + data () { |
| 63 | + return { |
| 64 | + response: '', |
| 65 | + options: { |
| 66 | + lineNumbers: true, |
| 67 | + theme: 'material' |
| 68 | + } |
| 69 | + } |
| 70 | + }, |
| 71 | +
|
| 72 | + created () { |
| 73 | + const response = { |
| 74 | + data: [ |
| 75 | + { |
| 76 | + id: '1', |
| 77 | + type: 'articles', |
| 78 | + attributes: { |
| 79 | + title: 'This project is awesome' |
| 80 | + }, |
| 81 | + relationships: { |
| 82 | + author: { |
| 83 | + data: { id: '1', type: 'author' } |
| 84 | + }, |
| 85 | +
|
| 86 | + comments: { |
| 87 | + data: [ |
| 88 | + { id: '1', type: 'comment' }, |
| 89 | + { id: '2', type: 'comment' } |
| 90 | + ] |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | + ], |
| 95 | +
|
| 96 | + included: [ |
| 97 | + { |
| 98 | + id: '1', |
| 99 | + type: 'author', |
| 100 | + attributes: { |
| 101 | + name: 'Anakin' |
| 102 | + } |
| 103 | + }, |
| 104 | + { |
| 105 | + id: '1', |
| 106 | + type: 'comment', |
| 107 | + attributes: { |
| 108 | + body: 'First!' |
| 109 | + } |
| 110 | + }, |
| 111 | + { |
| 112 | + id: '2', |
| 113 | + type: 'comment', |
| 114 | + attributes: { |
| 115 | + body: 'Second!' |
| 116 | + } |
| 117 | + } |
| 118 | + ] |
| 119 | + } |
| 120 | +
|
| 121 | + this.response = JSON.stringify(response) |
| 122 | + }, |
| 123 | +
|
| 124 | + computed: { |
| 125 | + formattedResponse () { |
| 126 | + try { |
| 127 | + return new JsonApiResponseConverter(JSON.parse(this.response)).formattedResponse |
| 128 | + } catch { |
| 129 | + return 'ERROR: Invalid JSON format.' |
| 130 | + } |
| 131 | + } |
| 132 | + } |
| 133 | +} |
| 134 | +</script> |
0 commit comments