Stop Writing Your Routes

Rate this content
Bookmark

The more you keep working on an application, the more complicated its routing becomes, and the easier it is to make a mistake. ""Was the route named users or was it user?"", ""Did it have an id param or was it userId?"". If only TypeScript could tell you what are the possible names and params. If only you didn't have to write a single route anymore and let a plugin do it for you. In this talk we will go through what it took to bring automatically typed routes for Vue Router.

Eduardo San Martin Morote
Eduardo San Martin Morote
30 min
12 May, 2023

Comments

Sign in or register to post your comment.

Video Summary and Transcription

Designing APIs is a challenge, and it's important to consider the language used and different versions of the API. API ergonomics focus on ease of use and trade-offs. Routing is a misunderstood aspect of API design, and file-based routing can simplify it. Unplugging View Router provides typed routes and eliminates the need to pass routes when creating the router. Data loading and handling can be improved with data loaders and predictable routes. Handling protected routes and index and ID files are also discussed.

Available in Español: Deja de Escribir tus Rutas

1. Designing APIs: Challenges and Considerations

Short description:

Designing API is really hard. It's one of the biggest challenges of any open source library. A good API makes errors hard to make and avoids context switch. Writing different versions of an API and considering the language used are important. The learning process for an API is subjective.

So yeah, my name is Eduardo. Good morning, London. Happy to be here another year. So as a Querty member but also as a developer and open source lover, I've been doing a lot of development of libraries, almost for seven years I think. So not only PNIA and Vue Router but also some of the libraries that are just adjacent to Vue itself. And I have been spending quite a lot of time thinking about how do we design the APIs for these libraries. Sometimes messing up, making mistakes, sometimes improving them afterwards, of course. But the bottom line is designing API is really hard, okay?

And I think it comes without saying that this is one of the biggest challenges of any open source library because you have to factor a lot of, I'm sorry, you have to take into account a lot of different factors. It's from how does these API changes, wait, sorry, I need to change the thing. This is going to be painful. Okay. So you have to take into account a lot of different things into account. Okay? You have to factor the users you have, are you building a new API? Are you not building a new API? And how the API feels to users, because at the end, an API being good or bad is very subjective. And I'm going to show you why.

So one of the things that I feel is very important to a good API is to make errors hard to make. Now, it might be obvious to some and completely new to others, but if you use a library where making errors is actually easy, it makes you feel dumb. Now, nobody likes to feel dumb when they're using something, are they? So it's definitely a big factor in my opinion of how an API can be good or not. Another big thing is avoiding context switch. Now, when we think about APIs, we first think about the code we need to write. But if the actual API goes beyond the code we write, it's not only the files, the folder that we have, but we can actually think about many other things that are part of the API because when we write code, when we develop a program, we're not only writing code itself. And then we have to cut it for different user experiences.

Now, this is very vague to be honest, but it's not the same to write a V1 of an API, so you only have new users, than writing a V2 of an API where you have existing users that are used to something. Also, you have to think about well, what language you are writing for is not the same writing in API in Java or Rust, than in JavaScript or TypeScript where things are evolving very quick. And I like to refer to this little joke, the user learning curve. So, the thing is our experience when learning something, which is also part of an API, the learning process is different and is subjective. So, the joke here is very simple actually. You have kind of like the time recently and then how much you can do with a tool. So, as you can see, Notepad, you can use it very quickly and you are not very efficient.

2. Different Tools and API Ergonomics

Short description:

Different tools have different levels of efficiency and productivity. Notepad is quick but not efficient. Pico allows for more functionality. Visual Studio has many shortcuts but can lead to decreased productivity. Vee, Veeam, and Nveam require learning but result in high productivity. Emacs and Spacemacs are powerful tools. This forms the basis of API ergonomics.

You have kind of like the time recently and then how much you can do with a tool. So, as you can see, Notepad, you can use it very quickly and you are not very efficient. Then you have Pico, which is just a terminal-based tool and you can do a little bit more things. Then you have Visual Studio, which you learn a lot of shortcuts, I think, and I believe the joke is that then you start digging too much into IDE and you spend too much doing things and then you become less productive. And then you have Vee or Veeam or Nveam, which basically you need to learn a lot before even being able to use it at all, but then you're very productive. And then you have Emacs and Spacemacs, which bend time and space, I think, because there is no way to do that in math. And so I'm going to use this as a base for what I call API ergonomics.

QnA

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

One Year Into Vue 3
Vue.js London Live 2021Vue.js London Live 2021
20 min
One Year Into Vue 3
Top Content
Vue 3 may still sound new to many users, but it's actually been released for over a year already. How did Vue 3 evolve during this period? Why did it take so long for the ecosystem to catch up? What did we learn from this process? What's coming next? We will discuss these questions in this talk!
Vue: Feature Updates
Vue.js London 2023Vue.js London 2023
44 min
Vue: Feature Updates
Top Content
The creator of Vue js gives an update on the new features of the technology.
TypeScript and React: Secrets of a Happy Marriage
React Advanced Conference 2022React Advanced Conference 2022
21 min
TypeScript and React: Secrets of a Happy Marriage
Top Content
TypeScript and React are inseparable. What's the secret to their successful union? Quite a lot of surprisingly strange code. Learn why useRef always feels weird, how to wrangle generics in custom hooks, and how union types can transform your components.
React's Most Useful Types
React Day Berlin 2023React Day Berlin 2023
21 min
React's Most Useful Types
Top Content
We don't think of React as shipping its own types. But React's types are a core part of the framework - overseen by the React team, and co-ordinated with React's major releases.In this live coding talk, we'll look at all the types you've been missing out on. How do you get the props type from a component? How do you know what ref a component takes? Should you use React.FC? And what's the deal with JSX.Element?You'll walk away with a bunch of exciting ideas to take to your React applications, and hopefully a new appreciation for the wonders of React and TypeScript working together.
Making Magic: Building a TypeScript-First Framework
TypeScript Congress 2023TypeScript Congress 2023
31 min
Making Magic: Building a TypeScript-First Framework
I'll dive into the internals of Nuxt to describe how we've built a TypeScript-first framework that is deeply integrated with the user's IDE and type checking setup to offer end-to-end full-stack type safety, hints for layouts, middleware and more, typed runtime configuration options and even typed routing. Plus, I'll highlight what I'm most excited about doing in the days to come and how TypeScript makes that possible not just for us but for any library author.
Nuxt on the Edge
Vue.js London 2023Vue.js London 2023
30 min
Nuxt on the Edge
Learn how to build a Vue application deployed to the edge to bring a blazing fast experience to your end users.

Workshops on related topic

React, TypeScript, and TDD
React Advanced Conference 2021React Advanced Conference 2021
174 min
React, TypeScript, and TDD
Top Content
Featured WorkshopFree
Paul Everitt
Paul Everitt
ReactJS is wildly popular and thus wildly supported. TypeScript is increasingly popular, and thus increasingly supported.

The two together? Not as much. Given that they both change quickly, it's hard to find accurate learning materials.

React+TypeScript, with JetBrains IDEs? That three-part combination is the topic of this series. We'll show a little about a lot. Meaning, the key steps to getting productive, in the IDE, for React projects using TypeScript. Along the way we'll show test-driven development and emphasize tips-and-tricks in the IDE.
Vue3: Modern Frontend App Development
Vue.js London Live 2021Vue.js London Live 2021
169 min
Vue3: Modern Frontend App Development
Top Content
Featured WorkshopFree
Mikhail Kuznetcov
Mikhail Kuznetcov
The Vue3 has been released in mid-2020. Besides many improvements and optimizations, the main feature of Vue3 brings is the Composition API – a new way to write and reuse reactive code. Let's learn more about how to use Composition API efficiently.

Besides core Vue3 features we'll explain examples of how to use popular libraries with Vue3.

Table of contents:
- Introduction to Vue3
- Composition API
- Core libraries
- Vue3 ecosystem

Prerequisites:
IDE of choice (Inellij or VSC) installed
Nodejs + NPM
Best Practices and Advanced TypeScript Tips for React Developers
React Advanced Conference 2022React Advanced Conference 2022
148 min
Best Practices and Advanced TypeScript Tips for React Developers
Top Content
Featured Workshop
Maurice de Beijer
Maurice de Beijer
Are you a React developer trying to get the most benefits from TypeScript? Then this is the workshop for you.In this interactive workshop, we will start at the basics and examine the pros and cons of different ways you can declare React components using TypeScript. After that we will move to more advanced concepts where we will go beyond the strict setting of TypeScript. You will learn when to use types like any, unknown and never. We will explore the use of type predicates, guards and exhaustive checking. You will learn about the built-in mapped types as well as how to create your own new type map utilities. And we will start programming in the TypeScript type system using conditional types and type inferring.
Deep TypeScript Tips & Tricks
Node Congress 2024Node Congress 2024
83 min
Deep TypeScript Tips & Tricks
Top Content
Workshop
Josh Goldberg
Josh Goldberg
TypeScript has a powerful type system with all sorts of fancy features for representing wild and wacky JavaScript states. But the syntax to do so isn't always straightforward, and the error messages aren't always precise in telling you what's wrong. Let's dive into how many of TypeScript's more powerful features really work, what kinds of real-world problems they solve, and how to wrestle the type system into submission so you can write truly excellent TypeScript code.
Going on an adventure with Nuxt 3, Motion UI and Azure
JSNation 2022JSNation 2022
141 min
Going on an adventure with Nuxt 3, Motion UI and Azure
WorkshopFree
Melanie de Leeuw
Melanie de Leeuw
We love easily created and deployed web applications! So, let’s see what a very current tech stack like Nuxt 3, Motion UI and Azure Static Web Apps can do for us. It could very well be a golden trio in modern day web development. Or it could be a fire pit of bugs and errors. Either way it will be a learning adventure for us all. Nuxt 3 has been released just a few months ago, and we cannot wait any longer to explore its new features like its acceptance of Vue 3 and the Nitro Engine. We add a bit of pizzazz to our application with the Sass library Motion UI, because static design is out, and animations are in again.Our driving power of the stack will be Azure. Azure static web apps are new, close to production and a nifty and quick way for developers to deploy their websites. So of course, we must try this out.With some sprinkled Azure Functions on top, we will explore what web development in 2022 can do.
Practice TypeScript Techniques Building React Server Components App
TypeScript Congress 2023TypeScript Congress 2023
131 min
Practice TypeScript Techniques Building React Server Components App
Workshop
Maurice de Beijer
Maurice de Beijer
In this hands-on workshop, Maurice will personally guide you through a series of exercises designed to empower you with a deep understanding of React Server Components and the power of TypeScript. Discover how to optimize your applications, improve performance, and unlock new possibilities.
 
During the workshop, you will:
- Maximize code maintainability and scalability with advanced TypeScript practices
- Unleash the performance benefits of React Server Components, surpassing traditional approaches
- Turbocharge your TypeScript with the power of Mapped Types
- Make your TypeScript types more secure with Opaque Types
- Explore the power of Template Literal Types when using Mapped Types
 
Maurice will virtually be by your side, offering comprehensive guidance and answering your questions as you navigate each exercise. By the end of the workshop, you'll have mastered React Server Components, armed with a newfound arsenal of TypeScript knowledge to supercharge your React applications.
 
Don't miss this opportunity to elevate your React expertise to new heights. Join our workshop and unlock the potential of React Server Components with TypeScript. Your apps will thank you.