Giter VIP home page Giter VIP logo

express-context's Introduction

Example of Express app with context

In this project you can find an example on how to inject information about the user that is executing the request, so we can filter the data easily.

You can access to this app through https://express-context.herokuapp.com

Data

We have three different entities:

Company

It has an id and a name

{
  id: 1,
  name: "Facebook"
}

User

It has an id, a first name, a last name and a company id that joins to a company.

{
  id: 121,
  firstName: "Mark"
  lastName: "Zuckerberg",
  company: 1
}

Project

It has an id, a name, a createdBy that joins to a user and a company id that joins to a user.

{
  id: 1223,
  name: "Facebook Messenger",
  createdBy: 121,
  company: 1
}

Authentication

Every request to this API requires a Authorization header. This is a simple base64 string built from a JSON object like this:

{"userId":1}

Some examples of authorization headers:

  • User 1: eyJ1c2VySWQiOjF9
  • User 2: eyJ1c2VySWQiOjJ9

Endpoints

Get /users

It returns all the users from the current user company.

curl --request GET \
  --url https://express-context.herokuapp.com/users \
  --header 'authorization: eyJ1c2VySWQiOjF9'

Get /projects

It returns all the projects from the current user company.

curl --request GET \
  --url https://express-context.herokuapp.com/projects \
  --header 'authorization: eyJ1c2VySWQiOjF9'

Post /projects

It creates a new project in the current user company and returns it.

Note: It doesn´t actually create the project as we are not connected to a database.

curl --request POST \
  --url https://express-context.herokuapp.com/projects \
  --header 'authorization: eyJ1c2VySWQiOjF9' \
  --header 'content-type: application/json' \
  --data '{
	"name": "new project"
}'

Get /projects/:id

It returns a project by the id. It only returns the project if it is in the current user company.

If not found returns a 404.

curl --request GET \
  --url https://express-context.herokuapp.com/projects/1 \
  --header 'authorization: eyJ1c2VySWQiOjF9'

express-context's People

Contributors

fernandocalsa 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.