Giter Site home page Giter Site logo

exercise-lsbu's Introduction

Synopsis

This is a basic webservice intended to work with the SoE website. This webservice gives the website the functionality to access internal data that otherwise shouldn't be accessible.

Installation

This code needs docker to run. Please install docker in your local environment before proceed. The installation might be different depending on the operating system you are running.

Once docker is installed, go to this folder and build the virtual machine with:

cd <path-to-this-code>
docker build -t soe .

Then execute the following code to run the virtual machine. The webservice will be mapped automatically to the port 80 of our local machine. (ensure no other process is running in the port 80 or it might conflict):

docker run --name soe-test -p 80:5000 -p 3306:3306 -v `pwd`:/storage/app/ soe

Note that the container has been created to run as an application. Once running it will show the standard output and terminating the process will terminate also the container.

To connect to the container we can use (this will allow us to execute commands from inside the container using the bash shell):

docker exec -it soe-test /bin/bash

If you need to rerun the virtual machine then we need to remove it first. Maybe the following commands will help you executing docker run again.

docker stop soe-test
docker rm soe-test

API Usage

Once the docker instance is up we should see the flask framework running in the port 5000, but this port is automatically mapped with the port 80 of the host.

Usually it's not recommended to write the API documentation in the README.md file as there are better tools to generate documentation from the code, but in this case we will do an exception.

There are some endpoints created around students administration:

  1. List students information
GET http://localhost/students
  1. List specific user information:
GET http://localhost/student/<student-id>
  1. Create a new user
POST http://localhost/student with form-data fields name, surname and birthdate
  1. Update an existing user
PUT http://localhost/student/<student-id> with form-data fields name, surname and birthdate
  1. Delete an existing user
DELETE http://localhost/student/<student-id>

Testing

This example comes with two different kinds of tests: unit tests and integration/behavioural tests to check every aspect of the code. The unit tests code coverage is not great as it's intended to be kept simple.

Unit testing

The tests are located under tests/ directory.

To run the tests first we have to connect with the container.

Once inside, we can execute from the command line:

cd /storage/app
pytest

The command will output the results of the tests. If any assertion didn't succeed, the system will show the error and a stack trace to know where the problem started.

Integration testing

The tests are located under tests_api/ directory.

The tests are build through a library called frisby and executed using jasmine. The dependencies are in a package.json file and installed through npm

The dependencies of nodejs are usually installed inside a folder called node_modules.

To run the tests first we have to connect with the container. And then execute:

cd /storage/app
./node_modules/jasmine-node/bin/jasmine-node . --verbose

Improvements

Several improvements can be done to the code:

  • Create a Response class that wraps any response from our webservice, so the format is consistent across any endpoint (status, message, etc. might be something present at all of them).

Contributors

Gorka Guridi [email protected]

exercise-lsbu's People

Watchers

James Cloos 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.