This guide walks you through creating your first coprocessor service and connecting it to Hive
Router.
At the end, you will have a working setup where Hive Router calls your external service during
request processing, and your service can either continue the request or stop it early with a custom
response.
Before you start
You need three things:
a running Hive Router
a valid supergraph.graphql
a small HTTP service that accepts and returns JSON
If you do not have a supergraph yet, you can use a test supergraph:
Hive Router sends a JSON payload with fields like version, stage, control, and optional
request data. Your service should return JSON with at least:
Minimal required response
{ "version": 1, "control": "continue"}
This tells the router to continue processing.
Let’s start by creating a small service in any language. It must expose one HTTP endpoint, for example
POST /coprocessor.
For local testing, run it on http://127.0.0.1:8081/coprocessor.
Example coprocessor service written in Go
package mainimport ( "encoding/json" "log" "net/http")type CoprocessorRequest struct { Version int `json:"version"` Stage string `json:"stage"` Headers map[string]string `json:"headers,omitempty"` Context map[string]interface{} `json:"context,omitempty"`}type CoprocessorResponse struct { Version int `json:"version"` Control interface{} `json:"control"` Headers map[string]string `json:"headers,omitempty"` Body interface{} `json:"body,omitempty"` Context map[string]interface{} `json:"context,omitempty"`}func main() { http.HandleFunc("/coprocessor", handleCoprocessor) log.Println("Coprocessor running on http://127.0.0.1:8081/coprocessor") log.Fatal(http.ListenAndServe("127.0.0.1:8081", nil))}func handleCoprocessor(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodPost { http.NotFound(w, r) return } var payload CoprocessorRequest if err := json.NewDecoder(r.Body).Decode(&payload); err != nil { writeJSON(w, CoprocessorResponse{ Version: 1, Control: "continue", }) return } log.Printf("Received coprocessor stage: %s", payload.Stage) writeJSON(w, CoprocessorResponse{ Version: 1, Control: "continue", })}func writeJSON(w http.ResponseWriter, response CoprocessorResponse) { w.Header().Set("content-type", "application/json") w.WriteHeader(http.StatusOK) if err := json.NewEncoder(w).Encode(response); err != nil { log.Printf("failed to write response: %v", err) }}
The example coprocessor handles the router.request stage. It checks whether the incoming request (inbound request to Hive Router instance) includes an Authorization header. If the header is present, it adds "auth.checked": true to the context. If not, it stops the request early with a 401 Unauthorized response.
Configure Hive Router to call your service
Right now, Hive Router is not configured to send anything to the coprocessor.
Next step is to add coprocessor to the config file: