Giter Site home page Giter Site logo

kitajs / minimal-example Goto Github PK

View Code? Open in Web Editor NEW
7.0 0.0 0.0 67 KB

๐Ÿ“ช A KitaJS boilerplate with the smallest possible number of files.

Home Page: https://kita.js.org

License: MIT License

TypeScript 100.00%
example getting minimal started kitajs docs endpoint js kita rest typescript

minimal-example's Introduction



Kita JS logo


KitaJS Minimal Example


Setup


๐Ÿ†• Try it out in under a minute at codespaces.new/kitajs/minimal-example.

๐Ÿ”ด Test out a live deployment at kitajs-minimal-example.up.railway.app.


You can also clone this repository locally:

# clone the repo
git clone https://github.com/kitajs/minimal-example.git app

# Cd into it
cd app

# Install dependencies
npm install

# Build the app
npm run build

# Start the app
npm start

Documentation

You can find the documentation at kita.js.org. This is a minimal example without any boilerplate or custom configuration, making it the best way to bootstrap your app without unnecessary setup.


Getting Started

Firstly, let's review everything you need to know to get started with KitaJS.

  1. Make sure your IDE is using the TypeScript project version. For VSCode, you can check that by opening the command palette and typing TypeScript: Select TypeScript Version and selecting Use Workspace Version. This will add useful debugging information to your IDE. You can test it by writing export function post(a: 1) {} into src/routes/index.ts, and you should see an error in your IDE.

  2. You can start your server by running npm run build and npm start.

  3. To add more routes, simply create a new file under src/routes. The file name will be the route path; for example, src/routes/users.ts will be /users. Afterward, export a function with one of the following names: get, post, put, delete, or all. By adding parameters to the newly created method, KitaJS automatically generates route validation, a Swagger schema, and types.

  4. You must encapsulate your parameters with one of Kita's generic methods: Body, BodyProp, Query, Path, Header, and many others that you can find in the documentation. You can also use FastifyInstance, FastifyRequest, and FastifyReply to access the Fastify instance, request, and reply objects. You can hover over each type to see its documentation and usage examples.


Boilerplate

  1. In your tsconfig, we added "plugins": [{ "name": "@kitajs/ts-plugin" }] to enable your editor to help you with IntelliSense.

  2. We only need @kitajs/runtime and fastify as production dependencies. You can see the only "configuration" file at src/index.ts. @fastify/swagger and @fastify/swagger-ui are only used to generate documentation at http://localhost:1227/docs.

  3. The build script calls kita build before tsc, which is the correct order because we need to read type information from the source files.

  4. You can run the test script to check if your code compiles correctly. --dry-run and --noEmit prevent KitaJS and TypeScript from emitting files, which is useful for testing.

  5. You can run npm run dev to instantly reflect your changes into your server. This is useful for development.

  6. Start your server by running node dist/index.js or npm start.

  7. Done! ๐ŸŽ‰


Swagger

After starting your server, you can access http://localhost:1227/documentation.

Swagger webpage


minimal-example's People

Contributors

arthurfiorette avatar devzolo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

minimal-example's Issues

Uploading swagger image

I do not want to include it in the repository because users will download/clone this repo often.

swagger

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.