Skip to content

Commit

Permalink
adding contract api blog post outline
Browse files Browse the repository at this point in the history
  • Loading branch information
harrisoncramer committed Aug 16, 2024
1 parent bfabcf9 commit 724b556
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 36 deletions.
7 changes: 7 additions & 0 deletions .astro/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ declare module 'astro:content' {
collection: "blog",
data: InferEntrySchema<"blog">
} & { render(): Render[".mdx"] },
"contract-driven-apis.mdx": {
id: "contract-driven-apis.mdx",
slug: "contract-driven-apis-in-typescript.mdx",
body: string,
collection: "blog",
data: InferEntrySchema<"blog">
} & { render(): Render[".mdx"] },
"creating-a-cli-in-javascript.mdx": {
id: "creating-a-cli-in-javascript.mdx",
slug: "creating-a-cli-in-javascript",
Expand Down
Binary file added src/assets/posts/contract.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 19 additions & 1 deletion src/consts.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
export const SITE_TITLE = 'harrisoncramer.me';
export const SITE_DESCRIPTION = 'Welcome to my website! This is my personal software engineering blog. I write about Go, Typescript, React, Vue, Javascript, Docker, Kubernetes, and lots of other interesting technologies.';
export const TAGS = ["neovim", "ci", "javascript", "microservices", "docker", "debugging", "golang", "astro", "typescript", "kubernetes", "circleci", "react", "terraform", "aws"] as const
export const TAGS = [
"neovim",
"ci",
"javascript",
"microservices",
"docker",
"debugging",
"go",
"astro",
"typescript",
"kubernetes",
"circleci",
"react",
"terraform",
"aws",
"api",
"neovim",
"lua"
] as const
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ The important thing to understand at the outset: Neovim *does not have debuggers

The language server protocol was built to standardize the way that different language servers communicate diagnostic information, type definitions, and other language metatdata to clients (often editors). This standardization makes it easier to connect Neovim to a variety of different language servers that are all implementing the same protocol.

Say you want to run a language server to give you autocomplete suggestions for a Golang codebase. Not only do you need to install the Golang language server (likely a separate binary, which will run as an independent process). You also need to set up Neovim so that it can communicate with that server, using the LSP, or Language Server Protocol.
Say you want to run a language server to give you autocomplete suggestions for a Go codebase. Not only do you need to install the Golang language server (likely a separate binary, which will run as an independent process). You also need to set up Neovim so that it can communicate with that server, using the LSP, or Language Server Protocol.

> If this is your first time setting up an LSP, please look elsewhere. This is not meant to be an exhaustive guide on how to set up an LSP.
Expand Down
3 changes: 2 additions & 1 deletion src/content/blog/building-gitlab-nvim.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ description: I've recently begun building the first open-source Gitlab client fo
heroImage: gitlab_and_neovim
imageDescription: An image of some code in an editor
slug: building-a-gitlab-client-for-neovim
tags: ["go", "lua", "neovim"]
---

You're hard at work, developing some feature, and your colleague sends you a DM: "Can you review my pull request?"
Expand Down Expand Up @@ -116,7 +117,7 @@ M.add_popup = function(type)
end
```

The key line to notice here is the `job.run_job` line, which kicks off an API call to Golang server's `/mr/reviewer` endpoint. The Go server processes the results into a Lua table, which is returned to the callback function as the `data` variable.
The key line to notice here is the `job.run_job` line, which kicks off an API call to Go server's `/mr/reviewer` endpoint. The Go server processes the results into a Lua table, which is returned to the callback function as the `data` variable.

What happens on the Go side of the fence?

Expand Down
25 changes: 0 additions & 25 deletions src/content/blog/contract-driven-apis-in-typescript.mdx

This file was deleted.

27 changes: 27 additions & 0 deletions src/content/blog/contract-driven-apis.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
title: Modeling Domain State with Contract Driven APIs
pubDate: 2024-08-15
description: Different approaches to enforcing schemas across API boundaries
imageDescription: A contract
heroImage: contract
tags: ["typescript", "javascript", "api", "go"]
slug: contract-driven-apis-in-typescript.mdx
---

One point of friction that often slows down engineering teams is a misunderstanding about API contracts.

Whether it's hotels or online dating, as engineering teams learn more about the domain they're working in, they'll need to adjust parts of the application's data model. Sometimes, this is to correct misconceptions that they originally baked into their APIs. Other times, it's to add new areas of the domain to that they haven't encountered before.

Bit by bit, the team's original mental model of the domain will shift, especially as APIs are deprecated or become bloated with old data.

When this happens, having a shared API contract across the engineering team is very valuable.

As requirements change and the application grows, the contract serves as a guidepost for engineers on both sides of the stack.

This blog outlines three possible approaches to enforcing and sharing a schema in order to enforce consistency in API design.

## OpenAPI and Code Generation

## TRPC

## JSON Schema
14 changes: 7 additions & 7 deletions src/content/blog/debugging-in-neovim.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ pubDate: 2022-12-21
description: Debug your applications directly within Neovim using the Debug Adapter Protocol, or DAP.
imageDescription: Debugging client in Neovim.
heroImage: bug
tags: ["neovim", "debugging", "golang", "javascript"]
tags: ["neovim", "debugging", "go", "javascript"]
slug: debugging-in-neovim
---

You'll probably spend more time debugging your next application than physically typing out the code required to run it. For a little while, the premier tool in the software industry for text manipulation, Neovim, was woefully behind IDEs like VSCode in it's debugger implementation. That's no longer the case.

The <a href="https://microsoft.github.io/debug-adapter-protocol/specification">Debug Adapter Protocol (DAP)</a> lets Neovim serve as a fully-featured debugger client, letting you attach to a running instance of your code, set breakpoints, inspect variables, examine call stacks, among other helpful debugging techniques.

This post is meant to serve as a basic guide for setting up a debugger in Neovim. Although it applies specifically to Golang, the principles are the same for debuggers for other languages, so long as they implement the Debug Adapter Protocol.
This post is meant to serve as a basic guide for setting up a debugger in Neovim. Although it applies specifically to Go, the principles are the same for debuggers for other languages, so long as they implement the Debug Adapter Protocol.

## What is DAP?

The Debug Adapter Protocol, or DAP, is a set of rules for how a debugger communicates with a client (usually an editor). Microsoft's <a href="https://microsoft.github.io/debug-adapter-protocol/">summary</a> puts it succinctly:

<p style="margin-left: 30px;">"The idea behind the Debug Adapter Protocol (DAP) is to abstract the way how the debugging support of development tools communicates with debuggers or runtimes into a protocol .. The Debug Adapter Protocol makes it possible to implement a generic debugger for a development tool that can communicate with different debuggers via Debug Adapters. And Debug Adapters can be re-used across multiple development tools which significantly reduces the effort to support a new debugger in different tools."</p>

Translating this to a specific language like Golang, we need the following pieces:
Translating this to a specific language like Go, we need the following pieces:

1. Our editor (Neovim)
2. The DAP "client" (the `nvim-dap` plugin)
Expand All @@ -32,7 +32,7 @@ Translating this to a specific language like Golang, we need the following piece

In order to debug a program you need a debugger. This is the tool, typically but not always a binary executable, that runs completely outside of Neovim and attaches to the running process you are trying to debug. To debug the application, I'm going to use the <a href="https://github.com/go-delve/delve">Delve</a> debugger.

The program that I'm going to "debug" is a simple TCP server implemented in Golang. You can get the same source code <a href="https://github.com/harrisoncramer/go-connect-tcp.git">from my Github, here,</a> or you can use your own program.
The program that I'm going to "debug" is a simple TCP server implemented in Go. You can get the same source code <a href="https://github.com/harrisoncramer/go-connect-tcp.git">from my Github, here,</a> or you can use your own program.

You can compile and run the TCP server by navigating to the root directory, and running:

Expand Down Expand Up @@ -96,7 +96,7 @@ You should see the following message:
No configuration found for `go`. You need to add configs to `dap.configurations.go` (See `:h dap-configuration`)
```

What's going on here? We've installed the debugger, and the debugger adapter for Neovim, but we haven't told nvim-dap what do to for Golang files yet. As the documentation states: "Neovim needs to instruct the debug adapter .. how to launch and connect to the debugee. The debugee is the application you want to debug."
What's going on here? We've installed the debugger, and the debugger adapter for Neovim, but we haven't told nvim-dap what do to for Go files yet. As the documentation states: "Neovim needs to instruct the debug adapter .. how to launch and connect to the debugee. The debugee is the application you want to debug."

Add the following to your configuration:

Expand Down Expand Up @@ -264,7 +264,7 @@ This works fine if you want to run the equivalent of `dlv debug .` locally. But
3. Attaching to a running debugger by picking it's PID
4. Attaching to an already running debugger running on a specific port

They look like this, and nvim-dap will ask me which of the configurations I'd like to use when I open it on a Golang file:
They look like this, and nvim-dap will ask me which of the configurations I'd like to use when I open it on a Go file:

```lua
local go = {
Expand Down Expand Up @@ -365,7 +365,7 @@ Now we can open up Javascript files and set breakpoints and inspect code the sam

We've now walked through the installation of the debugger, the debugger adapter, configuring the debugger, and adding a UI layer. If something goes wrong during your own setup, check Neovim's messages, and also DAP's logs with `:DapShowLog`.

It's worth mentioning that you can achieve configuration of the debug adapter for Go specifically with <a href="https://github.com/leoluz/nvim-dap-go">nvim-dap-go</a>, which will effectively write the `dap.configurations.go` and `dap.adapters.go` sections of your DAP configuration for you. You'll still need to install the debugger (delve) in order to use it, and the UI. If you prefer a more out-of-the-box configuration for Golang specifically, this plugin is quite nice.
It's worth mentioning that you can achieve configuration of the debug adapter for Go specifically with <a href="https://github.com/leoluz/nvim-dap-go">nvim-dap-go</a>, which will effectively write the `dap.configurations.go` and `dap.adapters.go` sections of your DAP configuration for you. You'll still need to install the debugger (delve) in order to use it, and the UI. If you prefer a more out-of-the-box configuration for Go specifically, this plugin is quite nice.

Finally, you can find my personal dotfiles <a href="github.com/harrisoncramer/nvim">on my Github account</a> and specifically my <a href="https://github.com/harrisoncramer/nvim/tree/main/lua/plugins/dap">debugger configuration</a>.

Expand Down
2 changes: 1 addition & 1 deletion src/content/blog/my-first-post.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Welcome to the blog section of my personal website! This is where I'll share wha

## What will you be writing about?

I'll be focused mostly on Typescript and Golang, but will also upload posts relating to Docker, Kubernetes, and other technologies I'm interested in. I'm also an avid Neovim user, and will ocassionally post about some of the things I'm learning about the editor—whether it's new plugins that speed up productivity, or built-in features that I'm learning to master.
I'll be focused mostly on Typescript and Go, but will also upload posts relating to Docker, Kubernetes, and other technologies I'm interested in. I'm also an avid Neovim user, and will ocassionally post about some of the things I'm learning about the editor—whether it's new plugins that speed up productivity, or built-in features that I'm learning to master.

Most of the posts will be for my own reference and will therefore be explanatory or otherwise instructional.

Expand Down

0 comments on commit 724b556

Please sign in to comment.