bingo-requests
Descriptions of network requests as used by Bingo. 📠
npm i -D bingo-requestspnpm add -D bingo-requestsyarn add -D bingo-requestsThe separate bingo-requests package includes types for the serialized request objects used in Concepts > Creations > requests.
These requests are type-safe when possible, most notably with GitHub Octokit endpoints.
Requests
All request objects may contain the following properties:
- id(optional): Unique ID for logging and to differentiate between requests to the same endpoint- See Merging > requestsfor how requests are merged
 
- See Merging > 
- silent(optional): Whether to skip logging errors if the request fails
- type(required): Which type of request this is, as either:- "fetch": A- CreatedFetchRequest
- "octokit": A- CreatedOctokitRequest
 
CreatedFetchRequest
Description of a request to send with fetch().
These additionally contain:
- init(optional): Any- RequestInitoptions to be sent as the second parameter to- fetch()
- url(required): URL to send the request to
For example, this object describes a GET request to https://create.bingo:
import { CreatedFetchRequest } from "bingo-requests";
export const request: CreatedFetchRequest = {  type: "fetch",  url: "https://create.bingo",};The id field can be useful to disambiguate two requests to the same URL.
Bingo by default merges fetch requests that have the same url data into one request.
If you need to send two requests to the same URL, you can give them different id values.
For example, these two objects describe separate POST requests to https://create.bingo:
import { CreatedFetchRequest } from "bingo-requests";
export const requests: CreatedFetchRequest[] = [  {    id: "first",    init: {      body: "(first)",      method: "POST",    },    type: "fetch",    url: "https://create.bingo",  },  {    id: "second",    init: {      body: "(second)",      method: "POST",    },    type: "fetch",    url: "https://create.bingo",  },];CreatedOctokitRequest
Description of a request to send with Octokit.
These additionally contain:
- endpoint: Octokit endpoint to send to
- parameters: Parameter data to attach to the request
For example, this object describes a request to add a label to a repository:
import { CreatedOctokitRequest } from "bingo-requests";
export const request: CreatedOctokitRequest = {  endpoint: "POST /repos/{owner}/{repo}/labels",  parameters: {    name: "good first issue",    owner: "JoshuaKGoldberg",    repo: "create-typescript-app",  },  type: "octokit",};The id field can be useful to disambiguate two requests to the same endpoint.
Bingo by default merges Octokit requests that have the same url data into one request.
If you need to send two requests to the same endpoint, you can give them different id values.
For example, these two objects describe separate requests to add labels to a repository:
import { CreatedFetchRequest } from "bingo-requests";
export const requests: CreatedFetchRequest[] = [  {    endpoint: "POST /repos/{owner}/{repo}/labels",    id: "first",    parameters: {      name: "good first issue",      owner: "JoshuaKGoldberg",      repo: "create-typescript-app",    },    type: "octokit",  },  {    endpoint: "POST /repos/{owner}/{repo}/labels",    id: "second",    parameters: {      name: "wontfix",      owner: "JoshuaKGoldberg",      repo: "create-typescript-app",    },    type: "octokit",  },];Octokit requests are generally type-safe, in that their types are generated from @octokit/types:
- endpointis typed as the keys of- Endpoints
- parametersis typed as the parameters for the endpoint- &- RequestParameters
