Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Pronounced as fee · row, a play on "hero" and "pheromone"
(that stuff some animals use to act as one).
Phero is the no-hassle and type-safe glue between your backend and frontend. TypeScript is at the core of it all. Development with Phero goes in these steps:
This boosts your frontend development:
💪 Use functions and domain models on the frontend, defined on the backend.
🧨 Handle errors on the frontend, thrown by the backend.
🤝 Stop assuming data is of the type you’re expecting. You know it is, period.
✅ No more mistakes with the specs of the API, like path, arguments or headers.
Backend development becomes a breeze as well:
🫶 Use TypeScript to define your domain models. No need for an extra language or DSL to learn and maintain, like with GraphQL or tRPC.
📋 Know when you break compatability with the frontend, before even running it: TypeScript has your back.
😶🌫️ No more outdated specs or documentation about endpoints (and what method, headers or arguments they expect).
🚀 The server can be deployed anywhere, either on one of the cloud platforms or a regular Node server.
Check out this introduction video to see how the basics work:
It all starts with a file called src/phero.ts
on your backend. Here's an example:
import { createService } from "@phero/server"
interface HelloMessage {
text: string
}
async function sayHello(name: string): Promise<HelloMessage> {
return {
text: `Hello, ${name}`,
}
}
export const exampleService = createService({
sayHello,
})
You can use any database or library you want, because this is a regular NodeJS environment. You can also structure your project in a way you prefer, as long as the Phero-file exports one or more services. Feel free to use any simple or advanced TypeScript feature to model out your domain and functions. In this example we'll keep it at a single service, exposing a function that returns a plain object.
Now, run npx phero
in your project directory. Phero will generate an SDK for your frontend, in a file called phero.generated.ts
. This includes a PheroClient
class which you can use to call the functions on your backend. From the generated file you can also import your models, which could come in very handy in some cases.
Here's an example of how that could look on your frontend:
import unfetch from "isomorphic-unfetch"
// Phero will generate a file called 'phero.generated.ts` with
// the PheroClient and the models you're using in your functions
// on the backend:
import { PheroClient, HelloMessage } from "../phero.generated"
// instantiate the PheroClient with your favorite fetch lib:
const phero = new PheroClient(unfetch)
// call your function on the backend. The return type of `sayHello`
// is `Promise<HelloMessage>`, like it would be with a local function:
const helloMessage = await phero.exampleService.sayHello("Steve Jobs")
console.log(helloMessage.text)
If sayHello
acts like a local function, you'd expect you could throw a custom error on the backend, and catch it on the frontend, right? With Phero, you can. Let's say we want to check for a minimum of 3 characters for the person we want to greet:
class NameTooShortError extends Error {
constructor(public readonly minimumLength: number) {
super()
}
}
async function sayHello(name: string): Promise<HelloMessage> {
if (name.length < 3) {
throw new NameTooShortError(3)
}
return {
text: `Hello, ${name}`,
}
}
To catch it on the frontend, you can import the error and handle it like you would with a local function:
import { HelloMessage, NameTooShortError } from "../phero.generated"
try {
const helloMessage = await phero.exampleService.sayHello(
"", // oops!
)
} catch (error) {
if (error instanceof NameTooShortError) {
alert(
`Name is too short, it should be at least ${error.minimumLength} characters`,
)
} else {
alert("Something went wrong")
}
}
A complete set of documentation could be found at: docs.phero.dev.
We are currently in Public Beta. Watch "releases" of this repo to get notified of major updates!
Phero is licensed as Apache-2.0.
FAQs
Full-stack type-safety with pure TypeScript
The npm package phero receives a total of 102 weekly downloads. As such, phero popularity was classified as not popular.
We found that phero demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.