Giter Site home page Giter Site logo

car_api's Introduction

Introduction

This PHP project is a graphQL experiment.

It acts as a proxy between a graphQL consumer and the CarQueryApi.

A local CSV file is also acting as a data source for cars data. It supports actually a few queries.

Installation

You need to have a typical LAMP stack to run this project.
The easiest way to do it is to use Vagrant to setup your environment.

Firstly, add an entry car-api.local pointing to 127.0.0.1 to the /etc/hosts file of your local machine.

Assuming Vagrant is installed, copy/paste the snippet below into create a file named Vagrantfile put in a dedicated folder.

Vagrant.configure("2") do |config|
  config.vm.box = "fkhannouf/UbuntuServer18.04LTS-BionicBeaver-LAMP7.2"
  config.vm.box_version = "0.0.1"
  config.vm.network "forwarded_port", guest: 80, host: 8080
  startupScript = <<-SCRIPT
    apt-get update
    while [ "$?" != "0" ]; do
      sleep 5
      apt-get update
      apt-get -q --yes install php7.2-mbstring
    done
  SCRIPT
  config.vm.provision "shell", inline: startupScript
end

When the setup is done, you can log into the vagrant box by typing :vagrant ssh

From here you can clone the project using :

git clone https://github.com/fkhannouf/car_api.git

Install the project dependencies :
composer install -d car_api
composer dump-autoload -o -d car_api

Now, get into the project directory then create a symlink in /var/www :
sudo ln -s /home/vagrant/car_api /var/www/

Create an Apache VirtualHost configuration file at /etc/apache2/sites-enabled/car-api.conf using the command below :

printf "<VirtualHost *:80>\nServerName car-api.local\nDocumentRoot /var/www/car_api\nErrorLog ${APACHE_LOG_DIR}/error.log\nCustomLog ${APACHE_LOG_DIR}/access.log combined\n</VirtualHost>" | sudo tee /etc/apache2/sites-enabled/car-api.conf

You can restart the Apache server :
sudo service apache2 restart

Running

The service is now reachable at http://car-api.local:8080

Tests

Here you'll find some typical queries that are supported in both GraphQL and Curl form :

Get Makes (manufacturer) list

{ 
  makes {
    name
  }
}

or

curl --request POST \
  --url 'http://car-api.local:8080/?=' \
  --header 'content-type: application/json' \
  --data '{"query":"{\n\tmakes {\n\t\tname\n\t}\n}"}'

Get Makes with name starting with "c"

{
  makes(startingWith:"c") {
    name
  }
}

or

curl --request POST \
  --url 'http://car-api.local:8080/?=' \
  --header 'content-type: application/json' \
  --data '{"query":"{\n\tmakes(startingWith:\"c\") {\n\t\tname\n\t}\n}"}'

Get cars with total cost of ownership < 3000

{
  cars(tcoBelow:3000) {
    make
    model
    trim
    tco
  }
}

or

curl --request POST \
  --url 'http://car-api.local:8080/?=' \
  --header 'content-type: application/json' \
  --data '{"query":"{\n\tcars(tcoBelow:3000) {\n\t\tmake\n\t\tmodel\n\t\ttrim\n\t\ttco\n\t}\n}"}'

Get cars with total cost of ownership > 5000

{
  cars(tcoAbove:5000) {
    make
    model
    trim
    tco
  }
}

or

curl --request POST \
  --url 'http://car-api.local:8080/?=' \
  --header 'content-type: application/json' \
  --data '{"query":"{\n\tcars(tcoAbove:5000) {\n\t\tmake\n\t\tmodel\n\t\ttrim\n\t\ttco\n\t}\n}"}'

Get cars for a specified manufacturer

{
  cars(make:"Peugeot") {
    make
	model
	trim
	tco
  }
}

or

curl --request POST \
--url http://car-api.local:8080/ \
--header 'content-type: application/json' \
--data '{"query":"{\n  cars(make: \"Peugeot\") {\n    make\n    model\n    trim\n    tco\n  }\n}\n"}'

car_api's People

Contributors

fkhannouf avatar

Watchers

 avatar  avatar

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.