stt-data
TypeScript icon, indicating that this package has built-in type declarations

0.0.26 • Public • Published

Using this package

Setup your environment

You can customize the environment in which services are run by updating the axios instance's defaults. Do that before anything in your code (after the imports in src/index.js if you use React/CRA) :

src/index.ts

import React from 'react';
import ReactDOM from 'react-dom/client';
import { App } from './App';
import { configure } from 'stt-data';

configure({
  baseURL: process.env.REACT_APP_API_URL,
  withCredentials: true,
  headers: {
    appId: process.env.REACT_APP_APP_ID,
    appPassword: process.env.REACT_APP_APP_PASSWORD
  }
});

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);

// ...

Consume the services

src/App.tsx

import { useState, useEffect } from 'react';
import { createUser, getUsers, User, UserInput } from 'stt-data';

export const App = () => {
  const [newUserProps, setNewUserProps] = useState<UserInput>({firstName: '', lastName: ''})
  const handleFormSubmit = () => createUser(newUserProps)

  const [users, setUsers] = useState<UserInput>([])
  useEffect(() => {
    getUsers().then(setUsers)
  }, []);

  return (
    // ...
  );
};

Making your client compliant to the latest version of STT API

npm i stt-data@latest

If you use TS, and the API has a breaking change, you will direclty know what are the portions of your code to apdapt. 👍

Developing this package

Starting

npm i

Scafolding

# Usage
npm run generateCRUD <entityName> <attributes>
# Examples
npm run generateCRUD Article "title:string body:string published:boolean mainPictureUrl?:string"
npm run generateCRUD Unicorn "name:string age:number"

Editing

If you use the CRUD generator, always check that what was generated is correct :)

Also, please follow those rules :

  • never use default exports
  • never create "index.ts" files yourself (they will be generated automatically when commiting or before publication)

Publishing

Ready to publish some updates of the API ?

npm run <update_type>

Just replace <update_type> by patch, major or minor following semver.

Readme

Keywords

none

Package Sidebar

Install

npm i stt-data

Weekly Downloads

2

Version

0.0.26

License

ISC

Unpacked Size

22.1 kB

Total Files

34

Last publish

Collaborators

  • comicscrip