Giter Club home page Giter Club logo

articleapi's Introduction

Article API

The first endpoint, POST /articles handle the receipt of some article data in json format, and store it within the service. The article will get an id and the date will be the datetime the article was received.

POST Payload

    {
          "title": "latest science shows that potato chips are better for you than sugar",
          "body" : "some text, potentially containing simple markup about how potato chips are great",
          "tags" : ["health", "fitness", "science"]
    }

The second endpoint GET /articles/{id} return the JSON representation of the article.

The final endpoint, GET /tags/{tagName}/{date} return the list of articles that have that tag name on the given date and some summary data about that tag for that day.

Running

Download:

    $ go get github.com/gambarini/articleapi

You must have the following installed to run the API server:

  • golang 1.10 (but any older version should be ok)
  • docker

From the articleapi folder execute the run script:

    $ run.sh

It will take a while to initialize the following:

  • MongoDB docker container.
  • Start the api server

If it all work, the API should be running on localhost:8000

Just Ctrl+C to terminate the server when you done. The script will cleanup the containers.

Considerations

Dates are always in the format yyyy-mm-dd

The POST /articles endpoint ignores any ID and Date posted in the payload. Both values are generated by the API based on the time the article is received.

Scalability

The GET /tags/{tagName}/{date} endpoint is not considering high traffic situations and is quering the articles database directly.

A better approach for scalling the tag queries would be building it as a separeted service with its own tags database. Then the database would be populated every time a new article is created (by services choreograph), resulting in a eventual consistent tags database offering better throughput for tags service.

Unit Tests

The only Unit test added was for the FindTag method in the ArticleRepository. This api was build in a bit over a hour and only tests for the more complex code were considered.

For the repository tests that require direct database access to make sense, a mongoDB docker container is started and managed within the test execution. Since mongoDB has the advantage of quick initialization without any configuration necessary, this approach to unit test is very favorable. It provide fidelity by running tests against the real DB while keep unit test execution farly quick.

All endpoints were tested with Postman during development and a Collection file was added to the repository for reference.

The lack of unit testes is in no way the ideal case, and is only consided due to the short time of development.

Concurrency

To improve execution time on the FindTag method the count query is executed in a go routine, concurrently to the main query fetching the articles.

Architecture

The project is structured for a separation of concerns, with the api server package containing the HTTP server logic, and the repo package abstracting the Database with a Repository Pattern. Finally the model package holds the objects that are part of the domain of this service.

Its useful to notice that in case of tests to the server package were added, the Repository abstraction would provide a easy way to Mock the Database. All by adding a ArticleRepository interface.

The article api is designed to be deployed as a microservice and can easely be run in a docker container.

articleapi's People

Contributors

gambarini avatar

Watchers

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