Giter VIP home page Giter VIP logo

api's Introduction

Cav API

A web API using GPRC/protobufs for main communication, but also supplying a more standard HTTP/JSON over grpc-gateway for legacy usage

Clients

Authentication

The API is guarded via an OAuth2 bearer token, which you can get via the 7Cav auth service

If you see an empty field for the API Key, go to the 'sessions' tab, and click 'Log out all sessions'. Then, sign in again as usual.

HTTP/JSON

We still maintain a simple HTTP API which routes to the underlying gRPC API. The more detailed endpoints are only accessible via the gRPC clients, so only use the HTTP API if you really need to and understand the trade-offs.

You can view the automatically generated documentation via api.7cav.us

If you want to 'try out' the API, ensure you use your bearer token by clicking the 'Authorize' button at the top of the page

Wrap the requests in whichever flavour of language/HTTP client you wish:

NodeJS

const axios = require('axios');
const token = "<your token>";

const client = axios.create({
  baseURL: 'https://api.7cav.us/api/v1',
  withCredentials: false,
  headers: {
    Accept: 'application/json',
    'Content-Type': 'application/json',
    Authorization: `Bearer ${token}`
  }
});

client.get("milpacs/profile/id/1")
    .then(res => {
        console.log(res.data)
    });

Go

package main

import (
    "context"
    "fmt"
    "golang.org/x/oauth2"
)

func main() {
    ctx := context.Background()
    client := oauth2.NewClient(ctx, oauth2.StaticTokenSource(&oauth2.Token{
        AccessToken: "<your token>",
        TokenType:   "Bearer",
    }))

    res, err := client.Get("milpacs/profile/id/1")
    if err != nil {
        panic(err)
    }
    fmt.Println(res)
}

gRPC

You probably came here for guidance on using the gRPC clients in your code. It depends on which language you're using, and if they are supported by gRPC.

An example client written in golang can be found in cmd/example.go and can be run via go run main.go example <id> to get milpac info for a specific user.

package main

import (
	"context"
    "crypto/tls"
    "fmt"
    "github.com/7cav/api/proto"
    "google.golang.org/grpc"
    "google.golang.org/grpc/credentials"
    "google.golang.org/grpc/credentials/oauth"
)

func main() {
    ctx := context.Background()
    token := "<token>"
    
    rpcCreds := oauth.NewOauthAccess(&oauth2.Token{AccessToken: token})

    // use TLS config to auto detect SSL/TLS cert from Api Host
    config := &tls.Config{
        InsecureSkipVerify: false,
    }

    opts := []grpc.DialOption{
        grpc.WithTransportCredentials(credentials.NewTLS(config)),
        grpc.WithPerRPCCredentials(rpcCreds),
        grpc.WithBlock(),
    }

    conn, _ := grpc.Dial("api.7cav.us:443", opts...)
    client := proto.NewMilpacServiceClient(conn)
    res, err := client.Profile(context.Background(), &proto.ProfileRequest{UserId: 1})
    if err != nil {
        panic(err)
    }
    fmt.Println(res)
}

Otherwise, follow the gRPC tutorials on using 'Client Side Code' and use the proto/milpacs.proto schema in your own code-bases.

Running

In production, we use a customized version of the docker-compose.yml you can see here. The nginx container in front is for handling SSL/TLS termination before we reach the gRPC server.That way internally we don't need to use TLS encryption(needed on client side due to sending bearer tokens)

The following should get you up and running. However you'll need a copy of the 7cav xenforo database imported into the mysql container!

make certs
docker-compose up -d

Development

So long as you have golang installed, you should be fine to run the following make commands to get setup with the required dependencies:

make install

This will also install Cobra, which is used for creating the boilerplate for each custom command on the generated binary.

When making changes to the proto file, be sure to run the relevant make file to regenerate the exported server interfaces:

You'll need to install the buf cli first from here

make generate

api's People

Contributors

jarvvski avatar nikpoliakov avatar syniron avatar vidsify avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

api's Issues

Record type error

Inconsistency between record types shown on 7cav website and API.

Example:

Record: Completed 62nd Combat Mission (Campaign Monday Madness September21. Operation Monday Madness 06SEP21)

https://7cav.us/rosters/profile/457/ shows record Type as Operation
Screen Shot 2021-09-12 at 22 44 09

https://api.7cav.us/api/v1/milpacs/profile/id/457 shows recordType as RECORD_TYPE_TRANSFER

{
      "recordDetails": "Completed 62nd Combat Mission (Campaign Monday Madness September21. Operation Monday Madness 06SEP21)",
      "recordType": "RECORD_TYPE_TRANSFER",
      "recordDate": "2021-09-07"
}

New Endpoints

We need to create some new endpoints that can expose the following data;

  • Search for user by username
    • This would be used by some service that does a lookup from battle metrics
  • Search for user by discord ID
    • Would be consumed by a future discord bot
    • We have the discord ID from the forum sync
  • Search via Position title
    • This could be a little more sketch. As it's going to involve fuzzy matching on Milpac names like '3/2/B/1-7'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.