Quickstart
Automatic Setup
We recommend creating a new Bridge app using create-bridge-app
, which sets up everything automatically for you. (You don't need to create an empty directory, create-bridge-app
will make one for you.) To create a project, run:
terminalbash
npx create-bridge-app@latest# orpnpm create bridge-app# oryarn create bridge-app
terminalbash
npx create-bridge-app@latest# orpnpm create bridge-app# oryarn create bridge-app
After the installation is complete:
- Run
cd ./your_project_name
- Run
npm i
orpnpm i
oryarn install
- Run
npm run dev
orpnpm dev
oryarn dev
to start the development server onhttp://localhost:8080
- Edit
index.ts
to start developing your server
For more information on how to use create-bridge-app, you can review the create-bridge-app documentation.
Manual Setup
Installations
Install bridge
and zod
in your project:
terminalbash
npm install bridge zod# oryarn add bridge zod# orpnpm add bridge zod
terminalbash
npm install bridge zod# oryarn add bridge zod# orpnpm add bridge zod
Create an index.ts file
Complete Bridge App with HTTP
server.tsts
import {handler ,initBridge } from 'bridge';// A handler can set an endpoint and validate user data such as the body, files,// request parameters or headers sent.consthelloEndpoint =handler ({resolve : () => 'Hello World',});// To define the routes for our project, we can create a routes object and place// our handlers inside. The keys of the object correspond to the path.constroutes = {hello :helloEndpoint ,};constport = 8080;constbridge =initBridge ({routes });consthttpServer =bridge .HTTPServer ();httpServer .listen (port , () => {console .log (`Listening on port ${port }`);});
server.tsts
import {handler ,initBridge } from 'bridge';// A handler can set an endpoint and validate user data such as the body, files,// request parameters or headers sent.consthelloEndpoint =handler ({resolve : () => 'Hello World',});// To define the routes for our project, we can create a routes object and place// our handlers inside. The keys of the object correspond to the path.constroutes = {hello :helloEndpoint ,};constport = 8080;constbridge =initBridge ({routes });consthttpServer =bridge .HTTPServer ();httpServer .listen (port , () => {console .log (`Listening on port ${port }`);});
Complete Bridge App with Express
server.tsts
import {handler ,initBridge } from 'bridge';importexpress from 'express';constroutes = {hello :handler ({resolve : () => 'Hello World',}),};constport = 8080;constapp =express ();constbridge =initBridge ({routes });app .use ('',bridge .expressMiddleware ());app .listen (port , () => {console .log (`Listening on port ${port }`);});
server.tsts
import {handler ,initBridge } from 'bridge';importexpress from 'express';constroutes = {hello :handler ({resolve : () => 'Hello World',}),};constport = 8080;constapp =express ();constbridge =initBridge ({routes });app .use ('',bridge .expressMiddleware ());app .listen (port , () => {console .log (`Listening on port ${port }`);});
You can test your endpoint by making an http call to POST http://localhost:8080/hello
. Refer to the route documentation for instructions on customizing the HTTP method.
Congratulations, you just launched your first Bridge server! 🥳
Client code generation and documentation
Connect your Bridge API to Bridge Studio
With the CLI
terminalbash
npx bridge-studio@latest# orpnpx bridge-studio@latest
terminalbash
npx bridge-studio@latest# orpnpx bridge-studio@latest
With the plateform: https://studio.bridge.codes
Fetch your client SDK
terminalbash
npx fetch-bridge-sdk@latest {username}/{projectName}
terminalbash
npx fetch-bridge-sdk@latest {username}/{projectName}
Access your generated documentation
You'll be able to access your complete generated documentation on https://studio.bridge.codes soon.
Please visit https://bridge.codes/studio for more information.