GithubHelp home page GithubHelp logo

gionoa / formula1api Goto Github PK

View Code? Open in Web Editor NEW
37.0 1.0 8.0 115 KB

Swift Package for accessing Formula 1 data from the Ergast API

License: MIT License

Swift 100.00%
f1 formula1 ergast-api motorsport

formula1api's Introduction

Formula 1 API

This Swift library provides endpoint access to Formula 1 data provided by the Ergast API. By using this library, you won't have to build the interactive layer yourself, and can just start consuming the data.

Installing / Getting started

Formula 1 API supports Swift Package Manager. To use SwiftPM, you should use the most recent version of Xcode to add this project.

Click File -> Swift Packages -> Add Package Dependency, enter Formula1API repo's URL. Or you can login Xcode with your GitHub account and just type Formula1API to search.

After select the package, you can choose the dependency type (tagged version, branch or commit). As of now, since there's no 1.0.0 release yet, choose master branch.

Initial Configuration

No configuration needed!

Deploying / Publishing

You can't run this library in your own server since it interacts with the live network. If you're interested in running your own server to fetch F1 data, check out this repository.

Features

Formula1API provides functions that allow you to access endpoints for data.

Currently, you can fetch:

  • Circuits (all, specified season)
  • Seasons
  • Constructors (all, specified season)
  • Race Schedule (specified season)
  • Race Results (specified season)
  • Qualifying Results (specified season),
  • Pit Stops (specified season),
  • Laps(specified season)

More endpoints will be accessible as development progresses.

Usage

Usage of this library within your app or package is simple.

Access endpoints via the Formula1API object.

Return closure example:

Formula1API.constructors(for: .year(2022)) { result in
    switch result {
    case .success(let constructors):
        print(constructors)
    case .failure(let error):
        print(error)
    }
}

Async-await example:

do {
    let constructors = try await Formula1API.constructors(for: .year(2022))
} catch error {
    print(error)
}

Licensing

The code in this project is licensed under MIT license.

formula1api's People

Contributors

gionoa avatar sjoness avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

formula1api's Issues

Add support for pagination

Ergast REST API responses (example) provide limit, offset, & total values for pagination. Add support for providing query items to specify a limit for each page.

Data returned from Library is not usable

Hello,

First of all, thank you for putting this together!
I added it to my project using Swift Package Manager and was able to use it to make calls to the Ergast API and print the resulting objects.

The problem is that the only object that is returned is the top-level one, and nothing else is accessible.
For example if I tried to get Circuit info for 2021, my code would be:

Formula1API.circuits(for: .year(2021)) { result in switch result { case .success(let circuits): print(circuits) case .failure(let error): print(error) } }

This works...BUT the "circuits" object can't be accessed (for example, I can't reach its "data" property because it is set to "internal" access-level only).

Unless I'm missing a step, this means I can't unpack the Circuits to get to an individual Circuit (or use the object in any other way).

I'd appreciate any help or guidance you can provide.

Thank you,

Marco

API implementation for self-hosted DB

Hi @gionoa, thanks for sharing this! I appreciate you setting this up, especially the models for Ergast responses.

I'm working against a self-hosted copy of the Ergast DB, and in your Readme under deploying and publishing, you recommended this nodejs repo. That repo works well for querying against my own db, but I wanted to point out that the url endpoints don't match up with those of the original Ergast API.

For example, getting drivers standings on Ergast:

https://ergast.com/api/f1/2008/driverStandings.json

Would have to be something like this in the node api:

http://localhost:5001/standings/drivers?year=2008

That being the case, I'd don't think think it would work as a drop in replacement to use your library against.

Are you using something else for your custom api? Or maybe I'm wrong and this library supports that url format?

Thanks again for sharing this.

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.